Jump to content

returning MySQL Max()


ravens_chance

Recommended Posts

I can get my mySQL query to run fine in phpMyAdmin, but can't get anything when I put it into my PHP code.

 

When I run the query in MySQL in phpMyAdmin I get the result:

 

MAX(jobID)

43

 

But, when I put this query into my code (with or without a variable) I get nothing. And everything downcode from it doesn't show up. What am I missing?

 

Ideally what I want to work:

$result = mysql_query("SELECT MAX(jobID) From job WHERE jobEmail='$jobEmail->email'");
while ($row = mysql_fetch_object($result)) {
    echo $row->jobID;
}
mysql_free_result($result);

Second attempt at code:

$result = mysql_query("SELECT MAX(jobID) FROM job WHERE jobEmail='[email protected]'";
while ($row = mysql_fetch_array($result)) {
	echo $row['MAX(jobID)'];
}   

 

Thank you

 

Link to comment
https://forums.phpfreaks.com/topic/188933-returning-mysql-max/
Share on other sites

Try using an alias instead

$result = mysql_query("SELECT MAX(jobID) as maxJobID FROM job WHERE jobEmail='[email protected]'";
$row = mysql_fetch_array($result);
echo $row['maxJobID '];

 

NOTE: if your query only returns one row/result, then you don't need to use a while loop.

Link to comment
https://forums.phpfreaks.com/topic/188933-returning-mysql-max/#findComment-997591
Share on other sites

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.