I’m having an issue with my array in the view file. What I”m trying to do is have it show the list of titles and and contenders for each title. As of right now its showing Vacant as the champion for each title AND TBD for each contender for each title when I have values that should be working but isn’t.
If the value for the championID is 0 in the table it should display Vacant if its not then it should get the champions name and display it. For each of the contenders if its a 0 in the database then it should display TBD if its not then it should display their name.
Here’s the query:
/**
* Get title champions
*
* @return object/NULL
*/
function getTitlesChampions()
{
$this->db->select('titlesList.titleName');
$this->db->select('rosterList.rosterName AS champion');
$this->db->select('con1.rosterName AS contender1');
$this->db->select('con2.rosterName AS contender2');
$this->db->select('con3.rosterName AS contender3');
$this->db->from('titlesChampions');
$this->db->join('titlesList', 'titlesList.id = titlesChampions.titlesListID');
$this->db->join('rosterList', 'rosterList.id = titlesChampions.championID', 'left');
$this->db->join('rosterList AS con1', 'con1.id = titlesChampions.contender1ID', 'left');
$this->db->join('rosterList AS con2', 'con2.id = titlesChampions.contender2ID', 'left');
$this->db->join('rosterList AS con3', 'con3.id = titlesChampions.contender3ID', 'left');
$query = $this->db->get();
if ($query->num_rows() > 0)
{
return $query->result();
}
return null;
}
Values inside of the titlesChampions table is this:
id - 1 titlesListID - 1 championID - 1 contender1ID - 1 contender2ID - 1 contender3ID - 1
id - 2 titlesListID - 2 championID - 1 contender1ID - 0 contender2ID - 0 contender3ID - 0
id - 3 titlesListID - 3 championID - 1 contender1ID - 0 contender2ID - 0 contender3ID - 0
I run a print_r of the array in the view file and this is what prints out:
Array
(
[0] => stdClass Object
(
[titleName] => Undisputed Heavyweight Title
[champion] => Kid Wonder
[contender1] => Kid Wonder
[contender2] => Kid Wonder
[contender3] => Kid Wonder
)
[1] => stdClass Object
(
[titleName] => Outlaw Title
[champion] => Kid Wonder
[contender1] =>
[contender2] =>
[contender3] =>
)
[2] => stdClass Object
(
[titleName] => Tag Team Titles
[champion] => Kid Wonder
[contender1] =>
[contender2] =>
[contender3] =>
)
)
<?php if (!is_null($titlesChampionsList)) { foreach ($titlesChampionsList AS $champion) {
echo '<tr>';
echo '<td>'.$champion->id.'</td>';
echo '<td>'.$champion->titleName.'</td>';
echo '<td>';
if ($champion->champion == 0)
{
echo 'Vacant';
}
else {
$champion->champion;
}
echo '</td>';
echo '<td>';
if ($champion->contender1 == 0)
{
echo 'TBD';
}
else {
$champion->contender1;
}
echo '</td>';
echo '<td>';
if ($champion->contender2 == 0)
{
echo 'TBD';
}
else {
$champion->contender2;
}
echo '</td>';
echo '<td>';
if ($champion->contender3 == 0)
{
echo 'TBD';
}
else {
$champion->contender3;
}
echo '</td>';
echo '<td style="text-align: center">';
$data = array('name' => 'user', 'value' => $champion->id);
echo '<a href="bios/edituser"><img src='.base_url().'assets/img/icons/packs/fugue/24x24/plus-circle.png /></a>';
echo '<img src='.base_url().'assets/img/icons/packs/fugue/24x24/cross-circle.png id="delete"/>';
echo '</td>';
echo '</tr>
'; } } ?>
Any ideas?
Assuming that array is in fact what is returned from the function: