SitePoint Sponsor

User Tag List

Results 1 to 7 of 7

Thread: MySQL Query

  1. #1
    You wanna' peice o' me! Automated's Avatar
    Join Date
    Nov 2001
    Location
    UK
    Posts
    338
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    MySQL Query

    Hi,

    I have a bit of a problem, i have a database with 200,000 records and need to do a sort of Merge.

    The records conatin two fields, they are WORD and DEFINITION.

    Now what i want to do it create a script that will export a file and in that file there would be
    Code:
    <category> 
    <pattern>what does {word} mean?<pattern> 
    <template>{word} means {definition}</template> 
    </category>
    But where is says {word} and {definition} it would replace that with the data in the DB.

    How hard would it be do get it to do this for say the first 1000 records and then export them to a TXT file on the server?

    Thanks a lot for your help.

    Matthew
    FreelanceForums.com - Do you Freelance ?
    Visit the Freelance Forums and participate in all areas of Freelance Chat

  2. #2
    SitePoint Wizard Chris82's Avatar
    Join Date
    Mar 2002
    Location
    Osnabrück
    Posts
    1,003
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You have to change the necessary fields but this should work:

    PHP Code:
    <?php
    mysql_connect
    ('localhost''user''pass') or die(mysql_error());
    mysql_select_db('yourdb');

    $query mysql_query('SELECT * FROM yourtable') or die(mysql_error());

    $data '';

    while (
    $row mysql_fetch_array($query))
    {
       
    $data .= "<category>\n";
       
    $data .= "  <pattern>What does {$row['word']} mean?</pattern>\n";
       
    $data .= "  <template>{$row['word']} means {$row['definition']}</template>\n";
       
    $data .= "</category>\n";
    }

    $fp fopen('/path/to/your/file.xml''w');
    fwrite($fp$data);
    fclose($fp);
    ?>

  3. #3
    You wanna' peice o' me! Automated's Avatar
    Join Date
    Nov 2001
    Location
    UK
    Posts
    338
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks! I have made a slight change to the File so it adds an extra line.


    Works Great! Thanks a lot.

    Matthew
    Last edited by Automated; Mar 16, 2003 at 15:38.
    FreelanceForums.com - Do you Freelance ?
    Visit the Freelance Forums and participate in all areas of Freelance Chat

  4. #4
    You wanna' peice o' me! Automated's Avatar
    Join Date
    Nov 2001
    Location
    UK
    Posts
    338
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have this working and it is all good, But i need one slight addition. How would i make it add a Bit of Text Specified by Me in header and footer of the page?

    What i need is the following code in the very top of the page;
    Code:
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <aiml>
    <!-- Aiml Set   -->
    And then this right at the bottom;
    Code:
    </aiml>
    Thanks for the help

    Matthew
    FreelanceForums.com - Do you Freelance ?
    Visit the Freelance Forums and participate in all areas of Freelance Chat

  5. #5
    SitePoint Guru
    Join Date
    Jan 2001
    Location
    Alkmaar, Netherlands
    Posts
    710
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    <?php
    $data 
    'This is where pre text will be added';
    while (
    $row mysql_fetch_array($query))
    {
    $data .= "<category>\n";
    $data .= " <pattern>What does {$row['word']} mean?</pattern>\n";
    $data .= " <template>{$row['word']} means {$row['definition']}</template>\n";
    $data .= "</category>\n";
    }
    $data .= 'This is where post text will be added';
    ?>
    Edit: never copy paste from colored texts
    Last edited by sylow; Mar 17, 2003 at 04:51.

  6. #6
    SitePoint Zealot Egghead's Avatar
    Join Date
    Feb 2002
    Posts
    197
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Cheers for sorting out that ugly code post Sylow. I suffer the same problem posting code as I use PHPEd. (I have to copy and paste code into Notepad or some bland text editor first!)
    Last edited by Egghead; Mar 18, 2003 at 12:15.

  7. #7
    You wanna' peice o' me! Automated's Avatar
    Join Date
    Nov 2001
    Location
    UK
    Posts
    338
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks Guys, I will give this a test out now



    Matthew
    FreelanceForums.com - Do you Freelance ?
    Visit the Freelance Forums and participate in all areas of Freelance Chat


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •