目前,我有,我用這個語句來獲得一切從服務以及其相關的表一個SQL和PHP的問題:MySQL的逗號分隔值
$db = $this->getDbo();
$query = $db->getQuery(true);
// Select the required fields from the table.
$query->select(
$this->getState(
'list.select', 'a.*'
)
);
$query->from('`#__services_service` AS a');
$query->where("a.zone");
$query->select('zone.name AS zone, zone.description AS zone_description, zone.price AS zone_price, zone.interval_recommended AS interval_recommended');
$query->join('LEFT', '#__services_zones AS zone ON zone.id = a.zone');
$query->select('category.icon AS category');
$query->join('LEFT', '#__services_categories AS category ON category.id = a.category');
但在區表我加盟,也有逗號分隔值'1,2',創建一個關聯數組並將服務分組到其區域後,單數服務僅進入單一區域,而不是在表中的值爲'1,2'時它應該在區域...我有一種感覺,這是因爲'zone.name AS zone'
,因爲那麼它只返回一個名稱,如果我說'zone AS zone'
它返回逗號分隔數字...
下面是如何排序的數組:
foreach($this->items as $item){
if(!isset($zones[ $item->zone ]))
$zone_items[ $item->zone] = array();
$zone_items[ $item->zone ][] = $item;
$zones[$item->zone] = array(
'zone' => $item->zone,
'zone_interval' => $item->interval_recommended,
'zone_description' => $item->zone_description,
'zone_price' => $item->zone_price,
'items' => $zone_items[$item->zone]
);
}
,我通過它顯示:
<?php foreach($zones as $zone): ?>
<div class="row-fluid zones-page">
<div class="row-fluid zone-title-block">
<div class="span4 zone-name"><h1><?php echo $zone['zone']; ?></h1></div>
<div class="span7 zone-description">
<?php echo $zone['zone_description']; ?>
<?php if($zone['zone_interval'] == 1): ?>
<span class="interval pull-right">Interval Recommended</span>
<?php endif; ?>
</div>
</div>
<?php foreach($zone['items'] as $items) :?>
<div class="row-fluid zone-services-contain">
<div class="span1"><div class="zone-icon"><?php //echo $items->category; ?></div></div>
<div class="span11 zone-services">
<h4><?php echo $items->name; ?></h4>
<div><?php echo $items->description; ?></div>
</div>
</div>
<?php endforeach; ?>
<div class="row-fluid zone-amount">
only <div><?php echo 'R' . $zone['zone_price']; ?></div>
</div>
</div>
<div class="bicycle-divider">
<div class="bicycle-icon"></div>
</div>
<?php endforeach; ?>
任何幫助是極大的讚賞。
的Services
表如下所示:
而且Zones
表:
桌子是什麼樣的? –
哪一個?..服務,區域或類別? –
區域表。 –