Jump to content
  • Checkout
  • Login
  • Get in touch


The e-commerce.

Quick SQL Query Question


Recommended Posts

Hey I am trying to get the max id from a table. I know the query works as I tried it in phpmyadmin and got the right answer but I dont know how to get the result from the query. here is the code

$sql = "select MAX(ethogram_id) as count from " . TABLE_ETHOGRAMS;
$max = tep_db_query($sql);
echo 'Max: ' . $max . '<br />';
echo 'Max: ' . $max['count'] . '<br />';


The first echo prints out Resource id#11 the second echo doesn't print out anything. What is the current syntax to get the result count from the query?



If I was crafty, this would be a funny signature.

Link to comment
Share on other sites

$sql = "select MAX(ethogram_id) as C from " . TABLE_ETHOGRAMS;

$max = tep_db_query($sql);

if ($r=tep_db_fetch_array($max)) echo 'Max: ' . $r['C'] . '<br />';



It's not good style to use SQL reserved words like "count" as aliases in queries.

Link to comment
Share on other sites


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

  • Create New...