我想让用户每天最多只能创建 10 个帖子。
这是我的 Controller :
$id_user=$this->session->userdata('id');
$sql ="SELECT COUNT(id_post) as max_post FROM post
WHERE post.id_user=$id_user
AND DATE(post.time)=DATE(NOW())";
$result = $this->db->query($sql);
if ($result > 10) //line number 17
{
//redirect to home
} elseif($result <= 10 ) //line number 20
{
//then do post
然后出现这样的错误:
A PHP Error was encountered
Severity: Notice
Message: Object of class CI_DB_mysql_result could not be converted to int
Line Number: 17
A PHP Error was encountered
Severity: Notice
Message: Object of class CI_DB_mysql_result could not be converted to int
Line Number: 20
有答案吗?
非常感谢...
最佳答案
if ($result > 10)
$result
是资源本身,您必须从中获取数据。 $result
本身并不是您要寻找的内容。从结果中获取所需字段。
例如
$row = $result->row();
if ($row->max_post > 10)
关于php - 为用户创建限制发帖,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27979074/