mySQL MAX() working from phpmyadmin but not from php script? -


edit: solved - usual, error code unrelated suspect code. using variable in place of table_name , getting switched wrong table prior running query.

for interested, of proposed solutions, original code, posted below, working me. help! sorry idiocy.

original post: have strange error occurring.

i trying maximum value mysql database column php script using following code:

$q = "select max(item_id) maxid table_name"; $q = mysql_query($q); while($row=mysql_fetch_assoc($q)){     $maxitemnum = $row['maxid']; } echo $maxitemnum; 

however, $maxitemnum gets echoed count of table rows rather maximum value 'item_id' column.

the strange thing is, when run following command via phpmyadmin, proper result (225):

select max(item_id) table_name 

any ideas issue? i'm stumped...

echo $maxitemnum = mysql_result(mysql_query("select max(item_id) maxid table_name limit 1"),0); 

one line good! @ least (:


Comments

Popular posts from this blog

how to insert data php javascript mysql with multiple array session 2 -

multithreading - Exception in Application constructor -

windows - CertCreateCertificateContext returns CRYPT_E_ASN1_BADTAG / 8009310b -