ianp Posted June 25, 2012 Share Posted June 25, 2012 I am an intern with a friend and he asked me to program a script where it gets the largest amount. I setup a function but am not sure how to go on from there, can anyone help me? By the way max_amt is suppose to be the max amount. $day = array('0','-1','-2','-3','-4'); foreach($day as $night) { if ($night === end($day)) { $end = ''; }else { $end = ','; } include('../Connections/default.php'); $date_m = date('m', strtotime(''.$night.' days')); $date_d = date('d', strtotime(''.$night.' days')); $date_Y = date('Y', strtotime(''.$night.' days')); mysql_select_db($database_default, $default); $query_uvs = "SELECT DISTINCT `ip` FROM `stats` WHERE `month` = '".$date_m."' AND `day` = '".$date_d."' AND `year` = '".$date_Y."'"; $uvs = mysql_query($query_uvs, $default) or die(mysql_error()); $total_uvs = mysql_num_rows($uvs); echo ''.$total_uvs.''.$end.''; } $max_amt = '1'; Quote Link to comment https://forums.phpfreaks.com/topic/264761-getting-the-max-amount-from-foreach/ Share on other sites More sharing options...
xyph Posted June 25, 2012 Share Posted June 25, 2012 Largest amount of what? Array - see max() SQL - SELECT whatever FROM table ORDER BY value DESC LIMIT 1 Quote Link to comment https://forums.phpfreaks.com/topic/264761-getting-the-max-amount-from-foreach/#findComment-1356918 Share on other sites More sharing options...
ianp Posted June 25, 2012 Author Share Posted June 25, 2012 This script makes the numbers from the array appear like this 1,2,3,4,5 I have tried max but it does not work. Quote Link to comment https://forums.phpfreaks.com/topic/264761-getting-the-max-amount-from-foreach/#findComment-1356919 Share on other sites More sharing options...
xyph Posted June 25, 2012 Share Posted June 25, 2012 It does work. You need to be more clear in what you're trying to do. The script displayed is mostly nonsense to us, and is poorly written. Quote Link to comment https://forums.phpfreaks.com/topic/264761-getting-the-max-amount-from-foreach/#findComment-1356920 Share on other sites More sharing options...
ianp Posted June 25, 2012 Author Share Posted June 25, 2012 The script I programmed is suppose to echo 1,2,3,4,5. The problem is when I try max(vcount(array('0','-1','-2','-3','-4'))) it just display 1,2,3,4,5. (I tried doing a function with the same foreach method shown in my previous post.) Quote Link to comment https://forums.phpfreaks.com/topic/264761-getting-the-max-amount-from-foreach/#findComment-1356937 Share on other sites More sharing options...
KevinM1 Posted June 25, 2012 Share Posted June 25, 2012 The script I programmed is suppose to echo 1,2,3,4,5. The problem is when I try max(vcount(array('0','-1','-2','-3','-4'))) it just display 1,2,3,4,5. (I tried doing a function with the same foreach method shown in my previous post.) ? So... it's doing what you want, but that's not what it's supposed to do? Quote Link to comment https://forums.phpfreaks.com/topic/264761-getting-the-max-amount-from-foreach/#findComment-1356939 Share on other sites More sharing options...
ianp Posted June 25, 2012 Author Share Posted June 25, 2012 I get <br%20/><b>Warning</b>:%20%20Wrong%20parameter%20count%20for%20max()%20in%20<b>/home/countryj/public_html/admin/content/dashboard.php</b>%20on%20line%20<b>13</b><br%20/> instead of the numbers Quote Link to comment https://forums.phpfreaks.com/topic/264761-getting-the-max-amount-from-foreach/#findComment-1356960 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.