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

Link to comment
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.