[eluser]mabright[/eluser]
I tried to avoid posting this as there are many other similar post but I have not found a solution.
Description: In my controller there are 2 processes; process 1 queries a list of nearby cities based on IP address. Process 2 finds venues located in the cities returned by process step 1.
In step 2 I loop through my array of cities while calling a model to get a list of venues for the current city(below):
Controller Code:
Code:
foreach($nearby_regions as $area)
{
$arr = $this->Venue_model->get_venues($area['city'],$area['region']);
if (empty($arr))
{
continue;
}
$venues[] = $arr;
}
Model Code:
Code:
function get_venues($city,$state)
{
$venues = array();
$sql = "SELECT * FROM `venue`
WHERE UPPER(`city`) = ?
AND UPPER(`state`) = ?";
$query = $this->db->query($sql, array(strtoupper(trim($city)),strtoupper(trim($state))));
if ($query->num_rows() > 0)
{
foreach ($query->result() as $row)
{
$venues[] = array('venue_id' => $row->venue_id,
'venue_name' => $row->venue_name,
'venue_desc' => $row->venue_desc);
}
}
return $venues;
}
My issue is that the array is deep and I want the venue data to be at the first level, instead it is at the 3rd level. My logic is working but I need a for loop before my for-each loop just to get to the data. See below.
Code:
Array
(
[0] => Array
(
[0] => Array
(
[venue_id] => 10027
[venue_name] => Test venue 1
[venue_desc] => Bar & Grill
)
)
[1] => Array
(
[0] => Array
(
[venue_id] => 10022
[venue_name] => Test venue 2
[venue_desc] => abc 123
)
[1] => Array
(
[venue_id] => 10029
[venue_name] => Test vinue 3
[venue_desc] => abc 123
)
)
)