Jump to content

selected MAX() value, but can't output it in PHP


ScrewLooseSalad

Recommended Posts

 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

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

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! :D

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.