Jump to content

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@company.com'";
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@company.com'";
$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

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.