Welcome Guest, Not a member yet? Register   Sign In
Mysql Results Conditional
#6

[eluser]bunoire14[/eluser]
Thanks Guys,

Heres how i did it, I think i followed the logic correctly.

I took the suggested route from @johnpeace and created a helper with the function in it:

Code:
//Change any Bool Result into Tick or Cross
    function boolean_icon($in)
    {
        $in = (int)$in; // cast as int just to be sure
        $out = array(0 => '<img src="'.base_url().'assets/img/site/cross.png" />', 1 => '<img src="'.base_url().'assets/img/site/tick.png" />');
        return $out[$in];
    }

As you can see I editied it slightly to return a full image tag.

I then called this helper in my controller like this:

Code:
class Staff extends Controller{
    
    //Site Staff Roster Page Method
        function roster()
        {
            $this->load->model('staff_model');
            $this->load->helper('ui');
            $data['staff_records'] = $this->staff_model->getStaff();
            $this->load->view('site_head');
            $this->load->view('staff_roster', $data);
            $this->load->view('site_foot');
        }
}

Then I used the method in the view like this:

Code:
&lt;?php foreach($staff_records as $row) :?&gt;
<tr>
    <td>&lt;?php echo $row->pid; ?&gt;</td>
    <td>&lt;?php echo $row->rank.' '.$row->fname.' '.$row->lname.' '; ?&gt;</td>
    <td>&lt;?php echo $row->cfs_role; ?&gt;</td>
    <td>&lt;?php echo $row->callsign; ?&gt;</td>
    <td>&lt;?php echo boolean_icon($row->efts); ?&gt;</td>
    <td>&lt;?php echo boolean_icon($row->one_fts); ?&gt;</td>
    <td>&lt;?php echo boolean_icon($row->two_fts); ?&gt;</td>
    <td>&lt;?php echo boolean_icon($row->three_fts); ?&gt;</td>
    <td>&lt;?php echo boolean_icon($row->four_fts); ?&gt;</td>
</tr>

&lt;?php endforeach; ?&gt;


This has the desired resuklt on the page itself, whether I have followed the MVC pattern doing it this way is another matter! LOL :red:

Thanks for the help Chaps,


Messages In This Thread
Mysql Results Conditional - by El Forum - 12-22-2010, 10:31 AM
Mysql Results Conditional - by El Forum - 12-22-2010, 11:11 AM
Mysql Results Conditional - by El Forum - 12-22-2010, 11:19 AM
Mysql Results Conditional - by El Forum - 12-22-2010, 09:26 PM
Mysql Results Conditional - by El Forum - 12-22-2010, 09:51 PM
Mysql Results Conditional - by El Forum - 12-23-2010, 08:26 AM
Mysql Results Conditional - by El Forum - 12-26-2010, 07:52 AM
Mysql Results Conditional - by El Forum - 12-26-2010, 07:57 AM



Theme © iAndrew 2016 - Forum software by © MyBB