1.

Solve : PHP > MySQL - Getting the ID from the last query?

Answer»

I am TRYING to make a forum so that when you post a new thread, you are navigated to it after it posts.

I was thinking this would work, but is there any way to just get the ID from the last posted thread with a certain username for field 'creator' ?

CODE: [SELECT]$q1 = mysql_num_rows(mysql_query("SELECT `id` FROM `threads`WHERE `creator`='$by' ORDER BY `posted_date` DESC, `posted_time` DESC"));
$q2 = mysql_query("SELECT * FROM `threads` WHERE `creator`='$by' ORDER BY `posted_date` DESC, `posted_time` DESC");
for ($x = 1; $x <= 1; $x++) {
   $m = mysql_fetch_array($q2);
   $last_post_id = $m['id'];
}
Maybe this?
http://w3schools.com/sql/sql_func_last.aspNevermind, I FOUND a different way to do it. Thanks for the SUPPORT though, kpac.Sheesh! No bothers......



Discussion

No Comment Found