我想要做的是創建一個數組,其中包含標題名稱列表,數據庫行的id,然後是冠軍和競爭者的名稱。對於冠軍和競爭者的價值觀,我需要做一個額外的查詢來檢索人員名單。如果冠軍的值爲0,則需要爲陣列添加Vacant,如果隊列0爲競爭者,則使用TBD作爲陣列。以下是我正在處理的內容,其中包括查詢和print_r輸出。帶查詢的數組對象
我的問題是「不能肯定我在哪裏/如何需要運行對每個標題的冠軍的那些價值觀和競爭者進行另外的查詢。
/**
* Get titles champions
*
* @return object/NULL
*/
function getTitlesChampions()
{
$this->db->select('titlesList.id');
$this->db->select('titlesList.titleName');
$this->db->select('titlesChampions.championID');
$this->db->select('titlesChampions.contender1ID');
$this->db->select('titlesChampions.contender2ID');
$this->db->select('titlesChampions.contender3ID');
$this->db->from('titlesChampions');
$this->db->join('titlesList', 'titlesList.id = titlesChampions.titlesListID');
$query = $this->db->get();
if ($query->num_rows() > 0) {
echo "<pre>";
print_r ($query->result());
echo "</pre>";
}
}
Array
(
[0] => stdClass Object
(
[id] => 1
[titleName] => Undisputed Heavyweight Title
[championID] => 1
[contender1ID] => 1
[contender2ID] => 1
[contender3ID] => 1
)
[1] => stdClass Object
(
[id] => 2
[titleName] => Outlaw Title
[championID] => 1
[contender1ID] => 0
[contender2ID] => 0
[contender3ID] => 0
)
[2] => stdClass Object
(
[id] => 3
[titleName] => Tag Team Titles
[championID] => 1
[contender1ID] => 0
[contender2ID] => 0
[contender3ID] => 0
)
)
這是什麼問題? – Sarfraz 2012-04-24 18:18:03
不太確定我應該如何創建附加標識符並執行第二個查詢。 – 2012-04-24 18:30:01