Jump to content


Photo

Minimum and Maximum Values


  • Please log in to reply
6 replies to this topic

#1 aenigma

aenigma
  • Members
  • PipPip
  • Member
  • 11 posts

Posted 03 May 2006 - 03:20 AM

This is what I have so far:
$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";

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

#2 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 03 May 2006 - 03:32 AM

$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'];

totally quick and dirty and could be done way better. but it works.
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#3 aenigma

aenigma
  • Members
  • PipPip
  • Member
  • 11 posts

Posted 03 May 2006 - 03:38 AM

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]

#4 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 03 May 2006 - 03:42 AM

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);


Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#5 aenigma

aenigma
  • Members
  • PipPip
  • Member
  • 11 posts

Posted 03 May 2006 - 03:43 AM

I fixed it, read above.

#6 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 03 May 2006 - 03:44 AM

yeh i saw that and edited it hoping you hadn't read it yet but gah! too late! :)
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#7 aenigma

aenigma
  • Members
  • PipPip
  • Member
  • 11 posts

Posted 03 May 2006 - 03:45 AM

Thanks a bunch for the help mate. You're a lifesaver.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users