Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Malfoy

macrumors 6502a
Original poster
Nov 1, 2005
688
2
Ok I've been at this for 48 hours and i've tried a few approaches, searched many a threads on other sites and while I feel I'm close I'm not there yet. What I want to do is run min/max on an array so I can obtain their respective values. the problem I'm having is getting a 'useable' array. This is been my most successful, yet still unsuccessful code so far:

PHP:
$Counter = mysql_num_rows($GetRatingsQuery);
echo 'Counter is ' . $Counter . '</br>';
//$Wait_Array = array();
for ($i=0; $i <= $Counter; $i++){
$GetRatings = mysql_fetch_array($GetRatingsQuery);
$Wait_Array[i] = $GetRatings['Waiter_Rating'];
echo ' Get Ratings value is ' .$GetRatings['Waiter_Rating']. '</br>';
echo 'Wait array value ' .$i. ' is ' . $Wait_Array[i] . '</br>';

}
echo 'Array output again <br>';
for ($i=0; $i <= $Counter; $i++){
echo 'Wait array value ' .$i. ' is ' . $Wait_Array[i] . '</br>';
}


The loop appears to work as its suppose to outputting:

Counter is 25
Get Ratings value is 4
Wait array value 0 is 4
Get Ratings value is 4
Wait array value 1 is 4
Get Ratings value is 4
Wait array value 2 is 4
Get Ratings value is 3
Wait array value 3 is 3
Get Ratings value is 5
Wait array value 4 is 5
Get Ratings value is 3
and repeats for 25 values

The second loop I run to see if it really holds anything outputs this:
Wait array value 0 is
Wait array value 1 is
Wait array value 2 is
Wait array value 3 is
Wait array value 4 is
Wait array value 5 is
up till 25. so needless to say when I run

PHP:
$SmallestWait_Rating= min($Wait_Array);
echo 'The lowest rating was' . $SmallestWait_Rating. '</br>';

it outputs:
The lowest rating about this waiter was

I've tried a
PHP:
while($GetRatings = mysql_fetch_array($GetRatingsQuery)){

and setting each item im looking for to a new variable like

PHP:
$Wait_rate =$Get_Ratings['Wait_Rate']

but when i run min on it gives me an error saying it needs at least one argument.

Summary:
I have a bunch of data I want to run min/max's on. I'd like to be able to store the data in a multi dimensional array but will store in a normal array if thats what it takes. I just need to be pointed in the right direction. What am I missing? Thanks in advance.
 
$ missing

You're missing the $ on the i variable in a couple spots, mostly notably,

Code:
$Wait_Array[[B]$i[/B]] = $GetRatings['Waiter_Rating'];

It's also in two other spots when you access this array. That seems to be the problem here.
 
You're missing the $ on the i variable in a couple spots, mostly notably,

Code:
$Wait_Array[[B]$i[/B]] = $GetRatings['Waiter_Rating'];

It's also in two other spots when you access this array. That seems to be the problem here.


The simple things I swear! putting $ where they needed to be fixed everything. :)
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.