Programming and Webmasters forum
HomeSearchRecent PostsLoginRegister Contact Us
 

Username  
Password
Pages: [1]   Go Down
  Email this topic  |  Print
0 Members and 1 Guest are viewing this topic.

Problem in fetching rows from mysql in php?

 
webmaster forum
JackyRock  Offline
 
New Poster
Posts: 2
Topics: 2
February 06, 2010, 04:03:19 AM

HI Friends,
I tried:
I inserted a row in my sql using php in the first web page and second web page i tried to retrieve it.
I got:
But in the next page i did not get the latest  inserted row.
When inserted the another row, i was able to get the first inserted row and not the latest row.

So every time i miss the last inserted row the first time and when then i was able to get it as soon as i insert another row.

How to solve this issue? Is it something related to commit i am missing here?

*** edited to remove personal promotion. we only allow promotions through signatures ***


« Last Edit: February 07, 2010, 12:29:11 AM by Admin »
 
webmaster forum
Admin  Offline
*
 
Expert Coder
Location: India
Gender: Male
Posts: 857
Topics: 77
WWW
February 07, 2010, 12:26:49 AM

If you are using some ID field/column in the table then you can make it as primary key and can set auto-increment property on that ID column. The auto-increment property on the column will make that column to have highest ID number. But for this you will need to have Data Type of the ID column as integer. So now, every time you insert a new row into the table, you can fetch the latest row by this ID column using a query:

Select MAX(ID) from table_name

Here the MAX(ID) will be the highest ID number in the table and therefore the latest row in the table.


There is one another way to achieve this, if you do not want to use ID column. You can use some Date filed/column in the table which will store the date and time at which the row is inserted in the table. So in this case, the row with the latest date will be the latest row in the table.



We are always happy to help you with programming...
 
  Email this topic  |  Print
Pages: [1]   Go Up
 
Jump to:  



Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC


Google visited last this page March 02, 2010, 04:59:04 PM

Valid XHTML 1.0 Transitional     Valid XHTML 1.0 Transitional