Jump to content

Archived

This topic is now archived and is closed to further replies.

aenigma

Minimum and Maximum Values

Recommended Posts

This is what I have so far:
[code]$maxvalue = "SELECT MAX(id) AS id FROM news";
$maxresult = mysql_query($maxvalue);
$minvalue = "SELECT MIN(id) AS id FROM news";
$minresult = mysql_query($minvalue);

echo "Max ID is: $maxresult - Mininum ID is: $minresult";[/code]

But, all I get is: Max ID is: Resource id #4 - Mininum ID is: Resource id #5

Share this post


Link to post
Share on other sites
[code]
$maxvalue = "SELECT MAX(id) AS id FROM news";
$maxresult = mysql_query($maxvalue);
$minvalue = "SELECT MIN(id) AS id FROM news";
$minresult = mysql_query($minvalue);

$max = mysql_fetch_array($maxvalue);
$min = mysql_fetch_array($minvalue);

echo "Max ID is: " . $max['id'] .  " - Mininum ID is: " . $min['id'];
[/code]

totally quick and dirty and could be done way better. but it works.

Share this post


Link to post
Share on other sites
Ahh, figured it out, you had a small error though. You gave me this:
[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]$maxvalue = "SELECT MAX(id) AS id FROM news";
$maxresult = mysql_query($maxvalue);
$minvalue = "SELECT MIN(id) AS id FROM news";
$minresult = mysql_query($minvalue);

$max = mysql_fetch_array([!--coloro:#FF0000--][span style=\"color:#FF0000\"][!--/coloro--]$maxvalue[!--colorc--][/span][!--/colorc--]);
$min = mysql_fetch_array([!--coloro:#FF0000--][span style=\"color:#FF0000\"][!--/coloro--]$minvalue[!--colorc--][/span][!--/colorc--]);

echo "Max ID is: " . $max['id'] . " - Mininum ID is: " . $min['id'];[/quote]

and it needed to be:
[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]$maxvalue = "SELECT MAX(id) AS id FROM news";
$maxresult = mysql_query($maxvalue);
$minvalue = "SELECT MIN(id) AS id FROM news";
$minresult = mysql_query($minvalue);

$max = mysql_fetch_array([!--coloro:#000099--][span style=\"color:#000099\"][!--/coloro--]$maxresult[!--colorc--][/span][!--/colorc--]);
$min = mysql_fetch_array([!--coloro:#000099--][span style=\"color:#000099\"][!--/coloro--]$minresult[!--colorc--][/span][!--/colorc--]);

echo "Max ID is: " . $max['id'] . " - Mininum ID is: " . $min['id'];[/quote]

Share this post


Link to post
Share on other sites
well that means that you are not executing a valid query. put

SELECT MIN(id) AS id FROM news

directly into phpmyadmin see if it returns a valid result. If it doesn't, then there's your problem. invalid query. If it does, then you may not be connecting to the database at all.

edit: my bad. i used the wrong variables. should be

$max = mysql_fetch_array($maxresult);
$min = mysql_fetch_array($minresult);

Share this post


Link to post
Share on other sites

×

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.