CodeIgniter Forums
Show a register database. - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Show a register database. (/showthread.php?tid=20310)



Show a register database. - El Forum - 07-05-2009

[eluser]Browser[/eluser]
Hello, i want to show a register of database.

return $query->result();

How can i show it without to used a foreach ?

In a foreach i use $query as $q { echo $q->total; }


Show a register database. - El Forum - 07-05-2009

[eluser]ChrisMiller[/eluser]
Not sure of your question exactly but do you mean something like this?

Code:
$result = $query->result_array();
for ($i=0; $i<count($result); $i++)
{
    echo $result[ $i ]['sqltable_field_name'];
}

or

Code:
$result = $query->result();
foreach ($result as $row)
{
    echo $row->sqltable_field_name;
}

If this is not what you are looking for maybe you could explain your question a little better.


Show a register database. - El Forum - 07-05-2009

[eluser]guidorossi[/eluser]
I think you're looking for something like:

Code:
$this->db->select('name, age');
$this->db->where('gender', $gender);
$query = $this->db->get('peope');

if ($query->num_rows() > 0)
{
$queryresult = $query->result_array();


$name = $queryresults['0']['name']; //0 to get only the first or unique

}