php - 为用户创建限制发帖

标签 php mysql codeigniter

我想让用户每天最多只能创建 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/

相关文章:

php - 使用 PHP 和 MySQL 的 Bootstrap 分页

php - 根据其他表信息从表中检索行

php - 使用Doctrine中的DriverManager和QueryBuilder正确测试连接

mysql - 关于index和mysql的一般问题

Jquery - CodeIgniter 如何为 blob 提供文件扩展名

CodeIgniter 不加载页面

php - Faker 软件包、数据库播种器问题

c# - Umbraco 会与大型网站合作吗?

php - 将选择下拉列表发送到另一个选择下拉列表

php - 无法通过ajax将参数发送到页面本身