Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 03-07-2007, 11:40 PM   PM User | #1
bunny1
New Coder

 
Join Date: Feb 2007
Posts: 92
Thanks: 1
Thanked 0 Times in 0 Posts
bunny1 is on a distinguished road
sql

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'];
}
bunny1 is offline   Reply With Quote
Old 03-07-2007, 11:42 PM   PM User | #2
sir pannels
Regular Coder

 
Join Date: Jun 2002
Posts: 905
Thanks: 23
Thanked 5 Times in 5 Posts
sir pannels is an unknown quantity at this point
Need to change the $row variable as you are using the AS to give it an alias in your query ..

change your code from
Quote:
echo $row['Product_ID'];
to
Quote:
echo $row['MaxID];
and you should be good
sir pannels is offline   Reply With Quote
Old 03-07-2007, 11:43 PM   PM User | #3
bunny1
New Coder

 
Join Date: Feb 2007
Posts: 92
Thanks: 1
Thanked 0 Times in 0 Posts
bunny1 is on a distinguished road
of course i feel silly now!!
thanks
bunny1 is offline   Reply With Quote
Old 03-07-2007, 11:45 PM   PM User | #4
sir pannels
Regular Coder

 
Join Date: Jun 2002
Posts: 905
Thanks: 23
Thanked 5 Times in 5 Posts
sir pannels is an unknown quantity at this point
anytime
sir pannels is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 11:51 PM.


Advertisement
Log in to turn off these ads.