How come this works in mysql but not in PHP?
$myquery = "SELECT max(id) FROM mboard"; $myresult = mysql_query($myquery); $row = mysql_fetch_object($myresult); print "$row->id is result";
I know the query works in MySQL but I can't fetch it as an object OR as an array. I'm trying to get the largest ID.
Thanks, C.
how about: $myquery = "SELECT id FROM mboard order by id asc limit 1";
you should get the highest id out of that
try your query like this:
SELECT max(id) as id FROM mboard;
That way, the max(id) row will be titled "id", as you're referencing it!
-Andy
you have several ways to do it <? $myquery = "SELECT max(id) FROM mboard"; $myresult = mysql_query($myquery); $row = mysql_fetch_row($myresult); print "$row[0] is result"; ?>
or
<? $myquery = "SELECT max(id) as id FROM mboard"; $myresult = mysql_query($myquery); $max=mysql_result($myresult,0,"id"); print "$max is result"; ?>