/    Sign up×
Community /Pin to ProfileBookmark

select the MAX value…

Hello, I´m trying to get the highest value of a column from a table, I´m doing:

$sql = “SELECT MAX(quant) FROM distrib”;
$maxProc = mysql_query($sql) or die(“Error”);

echo “MaxProc=”.$maxProc;

and the result I´m getting is:

MaxProc=Resource id #15

When I was supposed to get: MaxProc=20, which is the highest value of the field quant.

Can someone tell me what I´m doing wrong here? Thanks.

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@nooor83May 11.2006 — $sql = "SELECT MAX(quant) FROM distrib";

$maxProc = mysql_query($sql) or die("Error");

$data = mysql_fetch_array($maxProc);

echo $data[0];

Regards,

Noor
Copy linkTweet thisAlerts:
@Marlon_BrauthorMay 11.2006 — Thanks for your help,,, I have another question that you can probably help me. I have 4 registers in a field called: "quant", with the values: 1,1, 2 and 0 So when I use: SELECT MAX(quant) it returns "3" !!?? When it was supposed to be "2" Any idea of why that is happening? Does that function MAX not consider the value zero??
Copy linkTweet thisAlerts:
@nooor83May 12.2006 — as far as i understood is that you have a table and in that table you have a column called quant which has 4 values 0,1,1,2 ,

when you issue a "select max(quant)" statement..it will return 2 the maximum value.. of the column..

i dunno how you are getting 3 ?? if you don't have 3 value in your column ??
×

Success!

Help @Marlon_Br spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...