Jump to content

Recommended Posts

Hey all.

 

I have two different queries that I am running and I need to compare the results and join them together if they are the same.

 

I originally had the query setup to do a series of LEFT JOINs, but due to some changes in what needs to be displayed, that is no longer an option, and the result is two queries.

 

Both of the queries are being executed and all of the data put into arrays.

foreach($rows as $row)
{
foreach($speaker_array as $speaker)
{
	if($row['entry_id'] == $speaker['entry_id'])
	{
		array_push($row['speakers'], $speaker);
	}
}
}

 

The data from the first query is in the array "$speaker_array".  The data from the second query is in the array "$rows".

 

What needs to happen is this:

 

I need to loop through each $row record in the $rows array.  The FOREACH statement is taking care of that.  Then I need to go through each $speaker in the $speaker_array and compare the data in each element against a field in the $row.

 

If there is a match, then I need to CONCAT (or in this case, array_push) the data that is in the $speaker array into the current iteration of $row. 

 

Since there can be multiple matches for the IF statement, I decided to create a new array $row['speakers'] inside of $row.

 

When I do a print_r on the $rows array after this FOREACH clause ends, the $speaker data is not pushed onto ANY of the iterations of $row.

 

Any idea what I am doing wrong here?

 

Thanks.

Link to comment
https://forums.phpfreaks.com/topic/134376-php5-foreacharray-push-issue/
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.