poe Posted February 28, 2007 Share Posted February 28, 2007 i have a bunch of data i get from a mysql db to show banners on my site. i am trying to group the relevent data together into a heirarcchy i have assigned a 'zone' value to each banner (location of where to show on my page ie. top of bage, down the side etc...) the 'qty_show' is how many banners will show in that zone example zone1 will show 4 banners, zone2 will show 2 the structure i really want is: Array ( [zone1] => Array ( [qty_show] => 4 [info] => Array ( [0] => Array( [hits] => 4 [banner_id] => 4 [filename] => ckone.ca => ckone.ca [size_w] => 120 [size_h] => 90 ) [1] => Array( [hits] => 15 [banner_id] => 1 [filename] => ckone.ca => ckone.ca [size_w] => 120 [size_h] => 90 ) [2] => Array( [hits] => 17 [banner_id] => 7 [filename] => zoe.com => zoe.com [size_w] => 120 [size_h] => 90 ) ) ) ) ETC ..... like: -zone1 ----qty show(refers to num of banners to show in this zone) ----info (banner info) -------- banner specs are here (url, filename, h, w etc...) -------- banner specs are here (url, filename, h, w etc...) -------- banner specs are here (url, filename, h, w etc...) -------- ETC... depending on number of banners in zone. -zone2 ----qty show(refers to num of banners to show in this zone) ----info (banner info) -------- banner specs are here (url, filename, h, w etc...) -------- banner specs are here (url, filename, h, w etc...) -------- banner specs are here (url, filename, h, w etc...) -------- ETC... depending on number of banners in zone. i have tried 2 ways and failed both times. see below for my failures if i go: (which is close, but doesnt list out all the banners in each zone) foreach ($bannerAry as $k => $val) { $zoneAry['zone'.$val['zone_id']] = array( 'qty_show' => $val[qty_show], 'info' => array( 'hits' => $val[hits], 'banner_id' => $val[banner_id], 'filename' => $val[url], 'url' => $val[url], 'size_w' => $val[size_w], 'size_h' => $val[size_h], ), ); } // end foreach i get: Array ( [zone1] => Array ( [qty_show] => 4 [info] => Array ( [0] => Array ( [hits] => 66 [banner_id] => 5 [filename] => ckone.ca => ckone.ca [size_w] => 120 [size_h] => 90 ) ) ) [zone2] => Array ( [qty_show] => 2 [info] => Array ( [0] => Array ( [hits] => 55 [banner_id] => 9 [filename] => zoe.com => zoe.com [size_w] => 90 [size_h] => 60 ) ) ) ) and if i go... (which doest move 'qty-show' as part of the zone heirarchy, but leaves as part of the banner info) foreach ($bannerAry as $k => $val) { $zoneAry['zone'.$val['zone_id']] = array( 'qty_show' => $val[qty_show], 'hits' => $val[hits], 'banner_id' => $val[banner_id], 'filename' => $val[url], 'url' => $val[url], 'size_w' => $val[size_w], 'size_h' => $val[size_h], ); } // end foreach i get... Array ( [zone1] => Array ( [0] => Array ( [qty_show] => 4 [hits] => 4 [banner_id] => 4 [filename] => ckone.ca => ckone.ca [size_w] => 120 [size_h] => 90 ) [1] => Array ( [qty_show] => 4 [hits] => 15 [banner_id] => 1 [filename] => ckone.ca => ckone.ca [size_w] => 120 [size_h] => 90 ) [2] => Array ( [qty_show] => 4 [hits] => 17 [banner_id] => 7 [filename] => zoe.com => zoe.com [size_w] => 120 [size_h] => 90 ) [3] => Array ( [qty_show] => 4 [hits] => 22 [banner_id] => 2 [filename] => [email protected] => [email protected] [size_w] => 120 [size_h] => 90 ) [4] => Array ( [qty_show] => 4 [hits] => 36 [banner_id] => 3 [filename] => ckone.ca => ckone.ca [size_w] => 120 [size_h] => 90 ) [5] => Array ( [qty_show] => 4 [hits] => 66 [banner_id] => 5 [filename] => ckone.ca => ckone.ca [size_w] => 120 [size_h] => 90 ) ) [zone2] => Array ( [0] => Array ( [qty_show] => 2 [hits] => 9 [banner_id] => 6 [filename] => ckone.ca => ckone.ca [size_w] => 90 [size_h] => 60 ) [1] => Array ( [qty_show] => 2 [hits] => 42 [banner_id] => 8 [filename] => zoe.com => zoe.com [size_w] => 90 [size_h] => 60 ) [2] => Array ( [qty_show] => 2 [hits] => 55 [banner_id] => 9 [filename] => zoe.com => zoe.com [size_w] => 90 [size_h] => 60 ) ) ) Link to comment https://forums.phpfreaks.com/topic/40560-create-array/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.