Jump to content

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

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.