Jump to content

[SOLVED] MAX() returns 1


evanct

Recommended Posts

This:

 

$sql="SELECT MAX(session_id) FROM sessions";
echo dbQuery($sql);

 

prints 1. Even though the greatest session_id value is 9.

 

It doesn't matter what type of values the field has - integers, timestamps, strings, whatever - SELECT MAX() always returns 1.

 

Is there something I'm missing here?

Link to comment
https://forums.phpfreaks.com/topic/159027-solved-max-returns-1/
Share on other sites

It will print 1, because you are printing sql result, not query result.

You have to echo your row result like:

 

$sql="SELECT MAX(session_id) FROM sessions";
$q=mysql_query($sql);
$row= mysql_fetch_array($q);
echo $row['MAX(session_id)'];

 

Hope, it make sense.

Link to comment
https://forums.phpfreaks.com/topic/159027-solved-max-returns-1/#findComment-838661
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.