我在使用自动加载时遇到了麻烦。 例如:
我的模型:Dataload.php
public static function footer(){
$text = "Copyright © 2018 MyCompany";
return($text);
}
我的 View :view.php
<p class="xxx"><?php echo dataload::footer() ?></p>
可以显示。 但对于这个问题:
+------+------------+--------------+
| id | name | email_status |
+------+------------+--------------+
| 01 | Erick | send |
| 02 | Maya | send |
| 03 | Michael | pending |
+------+------------+--------------+
我的模型:Dataload.php
public function emailsend(){
return $this->db->query('SELECT COUNT(*) as total FROM user WHERE email_status = "send"');
}
我的观点:
<i class="ti ti-email"></i><span class="badge badge-primary"><?php echo dataload::emailsend() ?></span><span>Email</span>
那么,为什么数据不显示?
结果应显示“2”:
注意:请原谅我的英语:-)
最佳答案
更改模型中的函数:
public function emailsend(){
$q = $this->db->query('SELECT * FROM user WHERE email_status = "send"'); // you can select user_id here
return $q->num_rows(); // this will return count
}
然后在 View 中使用上面的函数。
NOTE: replace '*' with specific unique id. no need to select all the records.
关于php - 如何使用自动加载 Codeigniter 显示查询计数(*)中的数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48267989/