Link to home
Create AccountLog in
Avatar of Chris Andrews
Chris AndrewsFlag for United States of America

asked on

help with php/mysql statement please

I need to grab the highest amount in the column 'afterrebates', from the table 'cellphones', where updated = the indicated number.

I'm trying to use the script below, but i get: "You have an error in your SQL syntax near 'DESC LIMIT 1' at line 1."
------------------------
$cash_back_query= "SELECT afterrebates FROM cellphones WHERE updated = '1204982230' ORDER BY DESC LIMIT 1";

$results=mysql_query($cash_back_query);

echo $results;
-----------------------

Can you help?

Thanks,  Chris
SOLUTION
Avatar of gamebits
gamebits
Flag of Canada image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of Chris Andrews

ASKER

I want to get the highest number in the 'afterrebates' column, I thought I needed to put DESC (meaning descending order), I am wrong on that?
SOLUTION
Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
SOLUTION
Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Why do I get:

Resource id #3  

instead of the number I am looking for though?  With either of the above solutions.

So confused.
SOLUTION
Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
$cash_back_query= "SELECT MAX(afterrebates) as biggestvalue FROM cellphones WHERE updated = '1204982230' ";
$results=mysql_query($cash_back_query);
$row = mysql_fetch_array($results);
$biggestvalue = $row["biggestvalue"];
ASKER CERTIFIED SOLUTION
Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
As per yodercm's post you need add the mysql_fetch_array line, then you can reference the result as in the code snippet below:
$cash_back_query= "SELECT MAX(afterrebates) AS afterrebates FROM cellphones WHERE updated = '1204982230'";
 
$results = mysql_query($cash_back_query);
 
$results = mysql_fetch_array($results);
 
echo $results['afterrebates'];

Open in new window


Thank you all, working now!

oy, I'm going to have to post another question on how to award points for this answer :)

Gamebits answered first and followed up with working answers, though yodercm and LordOfPorts also chipped in with working solutions.

I'm thinking 400 to Gamebits, 50 each to yodercm and LordOfPorts .  Sound fair? Or should all the points go to Gamebits as the first to answer and also provided working follow up?
First isn't as important as working.  Share them to the people who provided you  the best and most helpful answers.
Thank you all.  I agree that it's not the first that is most important, but what's more helpful.  In this case, all of you were helpful in my understanding of what was going on, but when solutions use parts of someone elses solution it becomes challenging to reward points.  Not trying to start a fight, just saying it's difficult sometimes.  Wish I had more points to give to all you, but 500's the limit.  I went through each comment and tried to reward on that, so it's a little different from my first point proposal.
The points were fine :)  For most of us, it's not really that critical.  Just a little recognition and appreciation goes a long way.  Thanks for being concerned about the fairness :)