[SOLVED] - Arrays in Arrays from Queries

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
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

[SOLVED] - Arrays in Arrays from Queries

Post by anjanesh »

I have an array $arrMain[] which contains a mysql_fetch_assoc() array.
I've also added other fields from different queries.

Code: Select all

$PhotosRow=mysq_fetch_assoc(....);
$arrMain['Photo'][$i]=$PhotosRow // its in a loop
But this gives Notice: Array to string conversion in xxx\xxx.php on line xxx

Code: Select all

$PhotosRow is say Array([ID]=>5,[Data]=>xxx)
I thought I could get $arrMain['Photo'][$i]['ID'] and $arrMain['Photo'][$i]['Data'] but instead Im getting $arrMain['Photo'][$i]="A" (The first letter in Array (....))
Anyone know how to resolve this ?
Thanks
Last edited by anjanesh on Sat Aug 14, 2004 11:15 pm, edited 1 time in total.
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

Post by d3ad1ysp0rk »

are you sure PhotosRow is an actual array?
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

Post by anjanesh »

If $PhotosRow weren't an array it wouldn't show the Notice: Array to string conversion - would it ?
This is actual code and output :

Code: Select all

$PhotosRow=mysql_fetch_assoc($PhotosRes);
$arrInputFields['Photo'][$i]=$PhotosRow;
print_r($PhotosRow);
Notice: Array to string conversion in xxx on line xxx
Array ( [HouseID] => 3 [ImageURL] => HouseID3kitchen 1.jpg [View] => Kitchen [Words] => Kitchen with microwave oven, cupboards etc [Viewed] => 0 )
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

Post by anjanesh »

Solved. My mistake.
There was already an index Photo in arrMain so reassigning to an array wasn't seemed to be possible. I changed the new index to Photogallery and it worked
Post Reply