aenigma Posted May 3, 2006 Share Posted May 3, 2006 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 https://forums.phpfreaks.com/topic/8935-minimum-and-maximum-values/ Share on other sites More sharing options...
.josh Posted May 3, 2006 Share Posted May 3, 2006 [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 https://forums.phpfreaks.com/topic/8935-minimum-and-maximum-values/#findComment-32837 Share on other sites More sharing options...
aenigma Posted May 3, 2006 Author Share Posted May 3, 2006 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 https://forums.phpfreaks.com/topic/8935-minimum-and-maximum-values/#findComment-32839 Share on other sites More sharing options...
.josh Posted May 3, 2006 Share Posted May 3, 2006 well that means that you are not executing a valid query. putSELECT MIN(id) AS id FROM newsdirectly 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 https://forums.phpfreaks.com/topic/8935-minimum-and-maximum-values/#findComment-32841 Share on other sites More sharing options...
aenigma Posted May 3, 2006 Author Share Posted May 3, 2006 I fixed it, read above. Link to comment https://forums.phpfreaks.com/topic/8935-minimum-and-maximum-values/#findComment-32842 Share on other sites More sharing options...
.josh Posted May 3, 2006 Share Posted May 3, 2006 yeh i saw that and edited it hoping you hadn't read it yet but gah! too late! :) Link to comment https://forums.phpfreaks.com/topic/8935-minimum-and-maximum-values/#findComment-32843 Share on other sites More sharing options...
aenigma Posted May 3, 2006 Author Share Posted May 3, 2006 Thanks a bunch for the help mate. You're a lifesaver. Link to comment https://forums.phpfreaks.com/topic/8935-minimum-and-maximum-values/#findComment-32844 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.