Results 1 to 2 of 2

Thread: Append 1 table to another

  1. #1
    Join Date
    May 2007
    Posts
    1

    Append 1 table to another

    Hello,

    I'm using MYSQL4 with php4.4,
    I want to be able to order alphabetically information from several databases so then I can echo it to javascript with ajax.

    I tried doing it the only way I could think of: I create a temporary database,
    write all this information to it and then order that.

    Is there an easier way?

    Also, even this is giving me an error. Here is my code:

    <?php
    // Make a MySQL Connection
    mysql_connect(-.....-) or die(mysql_error());
    mysql_select_db("mydb") or die(mysql_error());

    $myname="nm1";
    $query = "SELECT Word, Translation FROM $myname ORDER BY word";
    $result = mysql_query($query) or die(mysql_error());
    while($row = mysql_fetch_array($result)){
    $tot=$tot+1;
    $res1[$tot]=$row['word'];
    $res2[$tot]=$row['translation'];
    }

    // Create a MySQL table in the selected database
    mysql_query("CREATE TABLE example(
    id INT NOT NULL AUTO_INCREMENT,
    word VARCHAR(20),
    translation VARCHAR(20))")
    or die(mysql_error());

    $count=$tot;
    $tot=0;
    while($tot<$count){
    $tot=$tot+1;
    mysql_query("INSERT INTO example
    (word, translation) VALUES($res1[$tot], $res2[$tot] ) ");
    or die(mysql_error());
    }
    ?>
    here is the error i get so far:

    Parse error: parse error, unexpected T_LOGICAL_OR on line 28

    could somebody tell me at least why i get this error?
    thanks

  2. #2
    Join Date
    May 2007
    Posts
    1
    You're getting that error because these two statements should really be only one statement:

    mysql_query("INSERT INTO example
    (word, translation) VALUES($res1[$tot], $res2[$tot] ) ");
    or die(mysql_error());

    Remove the first semi-colon, and the error should go away.

Posting Permissions

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