Forum Moderators: coopster

Message Too Old, No Replies

Get max value in MySQL table field

         

kiwibrit

4:30 pm on Dec 6, 2005 (gmt 0)

10+ Year Member



I have a 2-field table "pageref".

The fields are: "pagerefno" - which is index and primary key, and "url".

I need to find the max value in "pagerefno", so wrote the following code:


$query ="SELECT max(pagerefno) FROM pageref";
$result = mysql_query($query) or die ("Error in query: $query. " .
mysql_error());
$row = mysql_fetch_row($result);
echo row[0];

But this results in a blank screen. I'd be grateful for a steer, here.

dmorison

4:33 pm on Dec 6, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The $ is missing off $row in your echo statement - or is that just a typo in your post?... because other than that it looks fine...

kiwibrit

4:45 pm on Dec 6, 2005 (gmt 0)

10+ Year Member



Ouch!

I can do embarrassed.

Ooops.

Anyway, it works fine now. Thanks!