Jump to content

Minimum and Maximum Values


aenigma

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
Link to comment
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.
Link to comment
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]
Link to comment
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);

Link to comment
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.