0

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>
Deep Kakkar
  • 5,831
  • 4
  • 39
  • 75
Mahi
  • 180
  • 3
  • 15

1 Answers1

0

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
Hikmat Sijapati
  • 6,869
  • 1
  • 9
  • 19