CodeIgniter Forums
rows - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: rows (/showthread.php?tid=6091)



rows - El Forum - 02-14-2008

[eluser]mom_maj[/eluser]
hi i need help for that

i have a small project i need to bring data from DB and print it i in a table that is the code what wrong with that :

model:
function viwe()
{
$this->user_model->islogin();
$user_id = $this->session->userdata('user_id');
//connect to DB
$sql = "SELECT
*
FROM
list
WHERE
user_id= '$user_id'
";
$query = $this->db->query($sql);
if ($query->num_rows() == 0){
echo'no item in your list';
} else {
$row = $query->result();
$this->load->view('view');

}
}

and view:
<html>
<form method="POST" action="delete">
<table border='1'>
<tr><th>X</th> <th>Title</th> <th>Description</th><th>Status</th><th>Date</th><th>Action</th></tr>
&lt;?echo 'This Is The List Of Your Order';?&gt;
<tr><td>
&lt;?echo "&lt;input type='checkbox' name=\"checked[]\" value=\"$row-&gt;todo_id\">";?&gt;
</td><td>
&lt;?echo $row->title?&gt;
</td><td>
&lt;?echo $description?&gt;
</td><td>
&lt;?echo $status?&gt;
</td><td>
&lt;?echo $update_date?&gt;
</td><td>
&lt;?echo "<a href=\"http://localhost/codeigniter/index.php/todo/to_edit\"> edit</a>" ;?&gt;
</td></tr>

&lt;/form&gt;
<table>
<tr><td>&lt;input type="submit" value="Delete Todo"&gt;</td>
<td align="center"><a href = http://localhost/codeigniter/index.php/todo/back>GO back</a></td></tr>
</table>
&lt;/html&gt;


rows - El Forum - 02-14-2008

[eluser]xwero[/eluser]
Code:
$data['row'] = $query->row();
$this->load->view(’view’,$data);



rows - El Forum - 02-14-2008

[eluser]mom_maj[/eluser]
thank you for that but i have many row in DB that code give me just last row


rows - El Forum - 02-14-2008

[eluser]xwero[/eluser]
than you have to use $query->row() but then you also have to add a loop to your view file


rows - El Forum - 02-14-2008

[eluser]mom_maj[/eluser]
thank you for that