Need Help

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • TKB
    New Member
    • Nov 2006
    • 8

    Need Help

    I have the following code in order to retrieve the latest data inserted from mysql table. Does anybody know where is the problem?

    When a client submits the placeorder.php page, does anybody know how I can retrieve this date from mysql and present it in the viewmyorder.php page ?

    Thank you in advance for your effort.

    <?PHP
    include 'connectDB.php' ;

    $result = mysql(asbestos, "select categoryname from categories where categoryid=last _insert_id()" );
    $num = mysql_numrows($ result);
    $i = 0;

    while($i < $num) {

    echo mysql_result($r esult);

    $i++;}

    ?>
  • Atli
    Recognized Expert Expert
    • Nov 2006
    • 5062

    #2
    I dont think mysql() is a real function 0.o unless its a custom made fuctions from you?

    If I were trying to get the latest entry from a table Id do this

    [PHP] // Connect databaase
    $DB = @mysql_connect( $host, $user, $pass) or die("boohoo");
    mysql_select_db ($db) or die("boooo");

    // Query
    $RESULT = mysql_query("SE LECT <data> FORM <table> ORDER BY <column> DESC LIMIT 1");

    // Loop through the results and display
    // not that its needed with only one row but.. whatever
    while($row = mysql_fetch_arr ay($RESULT))
    {
    print_r $row;
    }[/PHP]

    Comment

    • ronverdonk
      Recognized Expert Specialist
      • Jul 2006
      • 4259

      #3
      You can only use LAST_INSERT_ID right after an INSERT statement.

      Ronald :cool:

      Comment

      Working...