Hi There -
I have three mysql tables. Am performing a join on two of them on an order_id then creating an array of arrays from each row. (Each row getting its own array.) The result is a series of objects whose prin_r looks like this...
newitems = Array
(
[0] => Array
(
[buyer_name] => mary
[message] => yo!
[item_title] => door
[iid] => 3539
)
[1] => Array
(
[giver_name] => jane
[message] => yo!
[item_title] => screen
[iid] => 3540
)
)
(where iid = item id)
Nothing terribly exciting and that part's working fine.
On the third table, if a condition is met (if there exists an 'iid' in the array) then I do a second query to get another number associated with the iid, the refid. This is in a third table.
If there is a refid, then I need to add it to the listed array of arrays so it would look like this:
newitems = Array
(
[0] => Array
(
[buyer_name] => mary
[message] => yo!
[item_title] => door
[iid] => 3539
[refid] => 9397 <-------------- refid!
)
[1] => Array
(
[giver_name] => jane
[message] => yo!
[item_title] => screen
[iid] => 3540
[refid] => 9395 <-------------- refid!
)
)
so I did a foreach loop over the item arrays...
foreach ($newitems as $newitem){
if ($newitem[nid]) {
//DB QUERY GOES HERE to get $refid
$newitem[refid] = $refid;
//print_r $newitem GOES HERE <----------first print_r
}
}
//print_r $newitems GOES HERE <----------second print_r
return $newitems
Here's what's weird: if I do a print_r on the $newitem arrays inside the foreach (the first print_r), so that each one gets printed out separately, then refid is added to each individual array. That's exactly what they're supposed to do.
But they don't stick! When I print_r the $newitems array (the second print_r) - no refid! It's the same as before I did the foreach loop to add the refid. It's just like the first example above!
Gah!
What am I doing wrong? I've been fiddling with this for more than a day and I'm flummoxed and my eyes are crossing.