Reputation: 129
I have a list of products. The products are stored in table products. Each product is located in a city. The name of the city is stored in the table cities.
The display of each product (thumbnail + name + price) is in a loop.
So first I extract the data by SQL query:
$db = JFactory::getDBO();
$sql_query = 'SELECT deal_id, name FROM deals,cities WHERE products.location_id = cities.id';
$result=mysql_query($sql_query);
I store everything in an Array:
$array_result = array();
while($row_deal = mysql_fetch_array($sql_query)){
$array_result[] = $row_deal;
}
Then start the loop to display the list of products. I have $item->id for identification of the product:
LOOP
......
......
What I have to put here to display the city?
echo ????
......
......
END LOOP
Upvotes: 1
Views: 117
Reputation: 392
foreach ($array_result as $key => $result){
echo $result->name_from_table;
}
Upvotes: 0
Reputation: 1246
You should do it with foreach.
<?php
$arr = array(1, 2, 3, 4);
foreach ($arr as &$value) {
$value = $value * 2;
}
// $arr is now array(2, 4, 6, 8)
unset($value); // break the reference with the last element
?>
Upvotes: 2