Jump to content

[SOLVED] Query and get last row


denoteone

Recommended Posts

smerny is right, the safest way to get the most recent inserted row's 'index' value is

 

ORDER BY `index` DESC LIMIT 1

 

Depending on the circumstances, you could also use mysql_insert_id.

 

'index' is a reserved word, you either have to rename that column or put backticks around it.

 

BTW, I don't see how you're using PHP to get the last row, so I'm moving this to MySQL Help (assuming that's what you're using).

sorry. Thanks Maq.

 

so would

$query  = "SELECT * FROM prices ORDER BY countkey DSC LIMIT 1";

 

 

$result = mysql_query($query)or die (mysql_error());

$row = mysql_fetch_array($result, MYSQL_ASSOC);

 

would this work? I am still getting an error

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'DSC LIMIT 1' at line 1

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.