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

[eluser]j4zzyh4ck3r[/eluser]
Code:
function get_last_ten_entries() {
            $query = $this->db->get('entries', 10);
            $i = 0;
            foreach ($query->result() as $row) {
                $entries[$i][0] = $row->User_Id;
                $entries[$i][1] = $row->User_Username;
                $entries[$i++][2] = $row->User_Password;
            }
            return $entries;
            // return $query->result();
        }

Can I get the current row instead using $i ? If I use $query->result() as the return value how to display it in a view, Thanks in advance Smile
#2

[eluser]BenKxK[/eluser]
If you use $query->result() you can pass it to the view e.g. $data['last_ten'] and then in the view you can call the info (in a foreach loop etc) as $last_ten->User_Username.
#3

[eluser]InsiteFX[/eluser]
Something like this.
Code:
function get_last_ten_entries()
{
    $entries = array();

    $query = $this->db->get('entries', 10);
    
    if ($query->num_rows() > 0)
    {
       foreach ($query->result_array() as $row)
       {
           $entries[] = $row;
       }
    }

    $query->free_result();
    return $entries;
}

InsiteFX
#4

[eluser]j4zzyh4ck3r[/eluser]
[quote author="BenKxK" date="1302156696"]If you use $query->result() you can pass it to the view e.g. $data['last_ten'] and then in the view you can call the info (in a foreach loop etc) as $last_ten->User_Username.[/quote]

[quote author="InsiteFX" date="1302179327"]Something like this.
Code:
function get_last_ten_entries()
{
    $entries = array();

    $query = $this->db->get('entries', 10);
    
    if ($query->num_rows() > 0)
    {
       foreach ($query->result_array() as $row)
       {
           $entries[] = $row;
       }
    }

    $query->free_result();
    return $entries;
}

InsiteFX[/quote]

Thanks for your help, it works :p




Theme © iAndrew 2016 - Forum software by © MyBB