Jump to content

select statement to get the last sr_number save


newphpcoder

Recommended Posts

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

post-101569-1348240339966_thumb.jpg

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");

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.