Welcome Guest, Not a member yet? Register   Sign In
Num_rows Question
#1

[eluser]Bionicjoe[/eluser]
I'm using num_rows() to check for results, and that is working.
However I would like to use the result to number each line of data returned.

My function may get 4 rows and I would like them displayed in reverse order as follows:
Update 4: BlahBlahBlahBlah
Update 3: BlahBlahBlah
Update 2: BlahBlah
Update 1: Blah

The MVC I have gets the right data, and sorts it correctly, but I can't figure out how to number it.

Model
Code:
function listoutageupdates($id)
    {
        
        $this->db->order_by("updateid", "desc");
        $query = $this->db->get_where('updates', array('outageid' => $id));
        $num = $this->db->count_all('updates');.
        if ($query->num_rows() > 0)
        {
            return $num->result();
            return $query->result();
            
        }
        if ($query->num_rows() == 0)
        {
            //TO BE ADDED LATER: Return a no results found message.
            return FALSE;
        }
    }

View
Code:
if ($updates):
        foreach ($updates as $update)
        {
            ?&gt;<table id="outageform">
                <col />
                    <tr><td>Update &lt;?php  echo $update->num; ?&gt;</td><td>&lt;?php echo  $update->text;?&gt;</td></tr>
            &lt;?php
        }
    else:
        ?&gt;<table id="outageform">
                <col />
                <tr><td></td><td><b>No updates found.</b></td></tr>
    &lt;?php endif; ?&gt;
</table>
#2

[eluser]WanWizard[/eluser]
This code is never going to work, trying to return two different values.

Just return the query result, and do something like:
Code:
if ($updates):
        $c = count($updates);
        foreach ($updates as $update)
        {
            ?&gt;<table id="outageform">
                <col />
                    <tr><td>Update &lt;?php  echo $c--; ?&gt;</td><td>&lt;?php echo  $update->text;?&gt;</td></tr>
            &lt;?php
        }
else:
        ?&gt;<table id="outageform">
                <col />
                <tr><td></td><td><b>No updates found.</b></td></tr>
&lt;?php endif; ?&gt;
</table>

or return the entire query object and then use num_rows() in your view instead of count().
#3

[eluser]Bionicjoe[/eluser]
*sigh*

So simple.

Thanks, WanWizard. I'm off to continue laboring in the Forest of N00bs.




Theme © iAndrew 2016 - Forum software by © MyBB