ScrewLooseSalad Posted April 10, 2013 Share Posted April 10, 2013 I have been struggling with this piece of code all morning and can't figure out why it won't output the result of the SQL $sql = "SELECT MAX(PartID) FROM `fullstocklist`"; $result=mysql_query($sql); if(!$result){echo "<p>SQL Error</p>";exit;} $row = mysql_fetch_row($result) or die(mysql_error()); echo "Maximum value is : ".$row['PartID']; $checktop = $row['PartID']; The query works, and returns the correct result in terminal, but I don't get an output after echo "Maximum value is :". The error must be in my php somewhere. Can anyone else spot it? It's really frustrating me Quote Link to comment https://forums.phpfreaks.com/topic/276768-selected-max-value-but-cant-output-it-in-php/ Share on other sites More sharing options...
mikosiko Posted April 10, 2013 Share Posted April 10, 2013 $sql = "SELECT MAX(PartID) AS PartID FROM `fullstocklist`"; Should take care of your issue Quote Link to comment https://forums.phpfreaks.com/topic/276768-selected-max-value-but-cant-output-it-in-php/#findComment-1423887 Share on other sites More sharing options...
ScrewLooseSalad Posted April 10, 2013 Author Share Posted April 10, 2013 $sql = "SELECT MAX(PartID) AS PartID FROM `fullstocklist`"; Should take care of your issue Its still not working I like your dog Quote Link to comment https://forums.phpfreaks.com/topic/276768-selected-max-value-but-cant-output-it-in-php/#findComment-1423888 Share on other sites More sharing options...
Solution mikosiko Posted April 10, 2013 Solution Share Posted April 10, 2013 I didnt notice that you are using mysql_fetch_row before.... you have 2 options : a) mantain the query as you have originally and replace $ row['PartID'] for $ row [0] Or b) replace mysql_fetch_row for mysql_fech_assoc and mantain the query using the alias of my previous post Quote Link to comment https://forums.phpfreaks.com/topic/276768-selected-max-value-but-cant-output-it-in-php/#findComment-1423892 Share on other sites More sharing options...
ScrewLooseSalad Posted April 10, 2013 Author Share Posted April 10, 2013 I didnt notice that you are using mysql_fetch_row before.... you have 2 options : a) mantain the query as you have originally and replace $ row['PartID'] for $ row [0] Or B) replace mysql_fetch_row for mysql_fech_assoc and mantain the query using the alias of my previous post superb! Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/276768-selected-max-value-but-cant-output-it-in-php/#findComment-1423907 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.