shortysbest Posted December 24, 2010 Share Posted December 24, 2010 I have a status system, built with ajax, and I need to get the unique id that the database assigns to the post and return it in the results that are appended to the page via javascript, however I'm not sure how the bessst way would be to do this? I have been doing this: ///variables that are sent to the database $session = $_COOKIE['id']; $uid = $_POST['id']; $post = $_POST['post']; $date = mktime(); //way I have got the unique id of this post $query = mysql_fetch_assoc(mysql_query("SELECT * FROM posts WHERE from_id='$session' AND to_id='$uid' AND post='$post' AND date='$date'")); $id = $query['id']; Although that does work, It feels like it might not always be accurate. Link to comment https://forums.phpfreaks.com/topic/222584-best-way-to-get-the-id-of-the-post-you-just-posted/ Share on other sites More sharing options...
BlueSkyIS Posted December 24, 2010 Share Posted December 24, 2010 after a record insert with mysql_query, you can get the id of that record with mysql_insert_id(); simple example: $sql = "INSERT INTO some_table SET post_text = '$post_text'"; mysql_query ($sql) or die(mysql_error()); $new_record_id = mysql_insert_id(); Link to comment https://forums.phpfreaks.com/topic/222584-best-way-to-get-the-id-of-the-post-you-just-posted/#findComment-1151130 Share on other sites More sharing options...
shortysbest Posted December 24, 2010 Author Share Posted December 24, 2010 Perfect! Thanks. Link to comment https://forums.phpfreaks.com/topic/222584-best-way-to-get-the-id-of-the-post-you-just-posted/#findComment-1151146 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.