php - 如何从数组中获取行? mysqli

标签 php mysql codeigniter mysqli

我正在使用 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/

相关文章:

php - 从 $_POST/$_SESSION 数组中删除所选项目

mysql - 验证具有多个 parent 和多个 child 的列表(图)

php - 如何在基于 SQL 语句的单个 Eloquent 模型中使用表和 View ?

php - 使用 RC4 和 base64 保护 arduino 和 PHP 之间的通信

php - GroupBy Laravel MySql 查询

mysql - 亚马逊网络服务 + ASP.NET MVC 3 + MySql

php - 从表中选择值更新其他表值 Codeigniter 问题

javascript - 如何在 facebook 共享器链接中传递自定义参数

php - Paypal 中的标准工作流程与 PHP codeigniter 集成

php - 在 PHP 中计算 mysql 的空列数