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. Quote Link to comment 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(); Quote Link to comment Share on other sites More sharing options...
shortysbest Posted December 24, 2010 Author Share Posted December 24, 2010 Perfect! Thanks. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.