jordz Posted February 27, 2010 Share Posted February 27, 2010 Hi All, Im recently new to the forum and need a little help with this array problem ive been stuck on for a few hours. I'm a newby really and trying to learn more and more. Ive tried using the foreach function but so far had no luck, as well as looking on php.net. Basically I have some code that has multiple arrays in it however I can't seem to get it from this (which is how it is now): code: require_once('config.php'); echo '<pre>'; $select = 'SELECT * FROM photos'; $runquery1 = mysql_query($select); while($photos = mysql_fetch_array($runquery1, MYSQL_ASSOC)) print_r($photos); Array ( [photo_id] => 2 [user_id] => 2 ) Array ( [photo_id] => 3 [user_id] => 2 ) to something along the lines of this: [0] => Array ( [photo_id] => 2 [user_id] => 2 ) [1] => ]Array ( [photo_id] => 3 [user_id] => 2 ) basically I want to be able to access each arrays array like so echo $photos['1']['user_id]; etc... any help would be much appreciated, thanks ever so much, Jordan Link to comment https://forums.phpfreaks.com/topic/193597-mysql-to-multidimensional-array/ Share on other sites More sharing options...
jl5501 Posted February 27, 2010 Share Posted February 27, 2010 ok so all you need to do is to load each extracted array into a master array. require_once('config.php'); $allphotos = array(); $select = 'SELECT * FROM photos'; $runquery1 = mysql_query($select); while($photos = mysql_fetch_array($runquery1, MYSQL_ASSOC)) { $allphotos[] = $photos; } Then you can address $allphotos like $allphotos[0]['user_id'] etc Link to comment https://forums.phpfreaks.com/topic/193597-mysql-to-multidimensional-array/#findComment-1019128 Share on other sites More sharing options...
jordz Posted February 27, 2010 Author Share Posted February 27, 2010 Absolutely Fantastic! Thank you very much! Jordan Link to comment https://forums.phpfreaks.com/topic/193597-mysql-to-multidimensional-array/#findComment-1019130 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.