This question already has an answer here:
I am working with codeigniter. I want to fetch a single row with passed index. If I pass 0
then first row should be display if 2
then second. etc
Here is my little code.
$qu['tid'] = mysqli_query($con , "select * from tablename");
$this->load->view('admin/panel1' , $qu);
view code.
<table>
<tr>
<th>ID</th>
<th>Name</th>
</tr>
<tr>
<td><?php echo $tid['id'];?></td> // given row if 1 or 2
<td><?php echo $tid['name'];?></td>// given row if 1 or 2
</tr>
</table>
</div>
Try using $this->db->get('table_name')->row_array()
returns first row in array format.
To fetch the specific row pass the row number as parameter.Like below
$row = $this->db->get('table_name')->row_array(2);//fetches the third row
Example
Controller:
$qu['tid'] = $this->db->get('table_name')->row_array();
$this->load->view('admin/panel1' , $qu);
view:
echo $tid['id'];//prints id