newphpcoder Posted April 10, 2012 Share Posted April 10, 2012 Hi.. I just want to know what is the code to get the last inserted row on database. I tried max and last_insert_id yet it did not solve my problem SELECT last_insert_id(sr_number), sr_date, Items, SubItems, ItemCode, DemandedQty FROM stock_requisition; it display all data from my database. SELECT max(sr_number), sr_date, Items, SubItems, ItemCode, DemandedQty FROM stock_requisition; it only display last row.. but I need to display all data with all data with same sr_number for example : 1204100002 I attach my sample data from my database: Thank you so much Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted April 10, 2012 Share Posted April 10, 2012 there are two ways to do this. 1. MySQL insert into my_table (...) values (...); set @i1 = (select last_insert_id()); select * from my_table where id = @i1; 2. PHP mysql_query("insert into my_table (...) values (...)"); $lid = mysql_insert_id(); mysql_query("select * from my_table where id = $lid"); 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.