ryanf Posted April 15, 2005 Share Posted April 15, 2005 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? Thanks If I was crafty, this would be a funny signature. Link to comment Share on other sites More sharing options...
FalseDawn Posted April 15, 2005 Share Posted April 15, 2005 $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 More sharing options...
ryanf Posted April 15, 2005 Author Share Posted April 15, 2005 FalseDawn, that worked great, thanks for the help! If I was crafty, this would be a funny signature. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.