我要做的是创建一个数组,其中包含标题列表,标题名称,数据库行的 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
)
)