php - 通过Codeigniter从MySQL表中获取数据

标签 php mysql codeigniter

我在从 codeigniter Controller 中获取此数据时遇到问题。

    $q = $this->db->get('offers_orders');
    $this->db->select('total');
    $this->db->where('order_number', $orderid);


    $orderdata = $q->result_array();

    $orderamount = $orderdata[0]['total'];

你发现这段代码有什么问题吗?

最佳答案

是的,尝试一下:

$this->db->select('count(*) as total', false);
$this->db->where('order_number', $orderid);
$q = $this->db->get('offers_orders');

或者,

$q = $this->db->select('count(*) as total', false)->where('order_number', $orderid)->get('offers_orders');

关于php - 通过Codeigniter从MySQL表中获取数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17569187/

相关文章:

mysql - 如何高效地从多个表中选择一致的数据

javascript - 单击链接javascript,codeigniter时如何更改事件类

php - mysql自身与2个字段的关系

php - 如何在 WordPress 中以编程方式重定向 URL?

php - 没有得到 popen 的完整响应

mysql - 将数据插入表时 Date_format 不起作用? (SQL)

mysql - 连接五个表

php - 使用ajax和jquery将数组发送到codeigniter(php) Controller ,并在现有加载页面(在任何div中)上加载页面

php - SMTP 错误(220-我们未授权使用此系统传输未经请求的 220 和/或批量电子邮件。)

php - 如何通过javascript访问数据库?