我正在使用 codeigniter。我想获取带有传递索引的单行。如果我通过0
那么第一行应该显示如果 2
然后是第二。等等
这是我的小代码。
$qu['tid'] = mysqli_query($con , "select * from tablename");
$this->load->view('admin/panel1' , $qu);
查看代码。
<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>
最佳答案
尝试使用 $this->db->get('table_name')->row_array()
以数组格式返回第一行。
要获取特定行,请传递行号作为参数。如下所示
$row = $this->db->get('table_name')->row_array(2);//fetches the third row
示例
Controller :
$qu['tid'] = $this->db->get('table_name')->row_array();
$this->load->view('admin/panel1' , $qu);
查看:
echo $tid['id'];//prints id
关于php - 如何从数组中获取行? mysqli,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42945788/