Jump to content

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


Go to solution Solved by mikosiko,

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

  • Solution

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.