alin19 Posted February 7, 2008 Share Posted February 7, 2008 i have this code, but i recive $max as my las record in that table, i must go and edit the last record and save it to get the real $max can you help me? $query="SELECT * FROM `$operator` LIMIT 0 , 30"; if ($r=mysql_query($query)) { while ($row = mysql_fetch_array($r)) { //$cupoane[]=$row['nr.cupoane']; $zile[]=$row['zi']; $cupoane[]=$row['nr.cupoane']; echo " "; } } $inrCupoane=count ($cupoane); $inreZi=count ($zile); $min=999; $max=0; for ($v=0;$v<$inreZi;$v++) { if ($max<$cupoane[$v]) $max=$cupoane[$v]; if($min>$cupoane[$v]) $min=$cupoane[$v]; } Link to comment https://forums.phpfreaks.com/topic/89882-solved-mysql-error/ Share on other sites More sharing options...
aschk Posted February 7, 2008 Share Posted February 7, 2008 i HATE to say it, but i think you're being a bit of a numpty here. I'm guessing (by looking at what you're doing) but i'd say you're looking for the MAX and MIN for nr.cupoane. You can do this using the SQL query and NOT php... SELECT MAX(nr.cupoane), MIN(nr.cupoane) FROM `$operator`; Link to comment https://forums.phpfreaks.com/topic/89882-solved-mysql-error/#findComment-460635 Share on other sites More sharing options...
alin19 Posted February 7, 2008 Author Share Posted February 7, 2008 if ($r=mysql_query($query)) { $min=MIN(nr.cupoane); $max=MAX(nr.cupoane); } and then can i use this to asign min and max to the value that i want? sorry but i'm trying to learn php, javascript and i let mysql at last, so i don't know how to make a query easyer Link to comment https://forums.phpfreaks.com/topic/89882-solved-mysql-error/#findComment-460639 Share on other sites More sharing options...
aschk Posted February 7, 2008 Share Posted February 7, 2008 I'll change my statement slightly: $query = "SELECT MAX(nr.cupoane) as 'max', MIN(nr.cupoane) as 'min' FROM `$operator`;"; if ($r=mysql_query($query)) { $row = mysql_fetch_assoc($r); $min=$row['max']; $max=$row['min']; } Link to comment https://forums.phpfreaks.com/topic/89882-solved-mysql-error/#findComment-460643 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.