Forum Moderators: coopster
$con = mysql_connect("localhost","dMyDB","pass");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("MyDB", $con);
$result = mysql_query("SELECT id FROM table_name");
while ($row = mysql_fetch_array($result)) {
$max_id=$row['id'];
mysql_query("UPDATE table_name SET name='testname' WHERE id='$max_id'");
}
mysql_close($con);
This code is working, but it selects all ID's and update the name. I have tried:
SELECT MAX(id) FROM table_name
SELECT TOP 1 FROM table_name
But none of that worked.
What am I doing wrong? And can anyone help me out?
Thanks in advance
PHP coders like to use mysql_insert_id() [us2.php.net] but I use that one as well, especially if there is no previous "query."