Posted By

deadmoon on 08/29/06


Tagged

mysql query last id


Versions (?)

Last if of mysql query


 / Published in: PHP
 

two ways of doing it. 2nd is best

  1. $new_sql = "select MAX(id) from reviews";
  2. $get_new_sql= mysql_query($new_sql) or die(mysql_error());
  3. $new_id = mysql_result($get_new_sql,"id");
  4.  
  5.  
  6. <?php
  7. $link = mysql_connect('localhost', 'mysql_user', 'mysql_password');
  8. if (!$link) {
  9. die('Could not connect: ' . mysql_error());
  10. }
  11.  
  12. mysql_query("INSERT INTO mytable (product) values ('kossu')");
  13. printf("Last inserted record has id %d\n", mysql_insert_id());
  14. ?>

Report this snippet  

You need to login to post a comment.