Comparing query results to previous array

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
dardsemail
Forum Contributor
Posts: 136
Joined: Thu Jun 03, 2004 9:02 pm

Comparing query results to previous array

Post by dardsemail »

Hi,

I have an application I'm working on that posts the results of various races. All of the race results are stored in a table and I am pulling the results to display on a page.

Here's my challenge:

1) The page displays the top female and the top male (or sometimes the top 3 for each sex).

2) Then it breaks down the various age groups and shows the top 3 in each age group for each sex. The challenge is that if you are in the top three overall, you cannot be in the top 3 in your age group.

So for the top overall, I have a query with a LIMIT of 3. Works fine.

What I need to be able to do is then compare the results for each age group with the results in the top 3 overall and if the racer exists in the top 3 overall, then move on to the next racer and check them.... etc...

Does that make sense?

What is the best way to do this? I am sure that I can compare the age group row results to the results in the array from the first query - I'm just now sure how to go about doing this?

Can someone please point me in the right direction? I certainly don't want anyone to write the code for me - but I'm not sure of the syntax needed to compare to previous array results.

Thanks so much!
dardsemail
Forum Contributor
Posts: 136
Joined: Thu Jun 03, 2004 9:02 pm

Post by dardsemail »

I think I'm getting somewhere... I have generated two arrays:

1) one stores the id's for the top three racers

2) the other stores the values for the top 6 racers (including the top three)

What I can't seem to do is accurately loop the arrays in order that I can compare and move on to the next array if the value exists in the first.

Here's what I thought would work - but it only does a comparison once:

Code: Select all

foreach ($FemaleResultsArray as $FemaleResultsArray)
			{
			echo $FemaleResultsArray.&quote;<br />&quote;;
				foreach ($FemaleCompArray as $FemaleCompArray)
					{
					echo $FemaleCompArray;
					}
			}
I've been wracking my brain and just can't seem to get it. Any suggestions?

Thanks so much!
Post Reply