Jump to content

Getting the max amount from foreach


ianp

Recommended Posts

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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?

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.