...

View Full Version : sql



bunny1
03-07-2007, 11:40 PM
Hi

Im trying to find the highest id in the primary key Product_ID in the database and assign it to a variable.
The sql brings back the correct result
But when i use it in php i get no result

Can anyone see whats wrong with this code??
Thanks

$query = "SELECT max(Product_ID) as MaxID from Prods";
$result = @mysql_query($query) or die(mysql_error());


while($row = @mysql_fetch_array($result))
{
echo $row['Product_ID'];
}

sir pannels
03-07-2007, 11:42 PM
Need to change the $row variable as you are using the AS to give it an alias in your query ..

change your code from

echo $row['Product_ID'];

to

echo $row['MaxID];

and you should be good :)

bunny1
03-07-2007, 11:43 PM
of course i feel silly now!!
thanks

sir pannels
03-07-2007, 11:45 PM
anytime :)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum