我有這段代碼。基本上,它應該返回基於位置和什麼位置的用戶看了...
我試圖找出如何縮短這個執行時間繳費作業列表...
$cities = $this->getChildren($location->city_id);
foreach ($cities as $child) {
$grandChildren = $this->getGrandChildren($child, false);
foreach ($grandChildren as $grandChild) {
$cities[] = $grandChild;
}
}
$menu = $this->getPositionChildren($postion);
$menu[] = $postion->menu_id;
// var_dump($cities);
foreach ($cities as $city) {
$city_id = (!empty($city) ? "AND FIND_IN_SET('{$city}', town)" : '');
foreach ($menu as $key) {
$menu_id = (!empty($key) ? " AND FIND_IN_SET('{$key}', category_id)" : '');
$queries[] = "SELECT ponuka_id as id FROM " . TABLE_PREFIX . "ponuky WHERE 1 {$city_id} {$menu_id} AND `published` = '1' ORDER BY `date` DESC";
foreach ($queries as $query) {
$result = mysql_query($query);
if (!$result) {
return false;
}
while ($row = mysql_fetch_object($result)) {
if (!in_array($row->id, $this->_joblist, true)) {
$this->_joblist[] = $row->id;
}
}
}
}
上面的代碼可以很容易地運行超過1000個查詢,並且您可以想象,這需要時間......很長一段時間......有關如何改進此操作的任何提示?
從循環中刪除您的查詢! –
避免使用FIND_IN_SET()....一個更好的規範化數據庫可以正確索引,然後數據庫可以使用這些索引 –
看起來你必須標準化你的數據庫 – Jens