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 Link to comment https://forums.phpfreaks.com/topic/260660-select-statement-to-get-the-last-sr_number-save/ 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"); Link to comment https://forums.phpfreaks.com/topic/260660-select-statement-to-get-the-last-sr_number-save/#findComment-1335945 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.