为用户创建限制过帐

时间:2015-01-16 07:21:53

标签: php mysql codeigniter

我想让用户每天最多可以创建10个帖子。

这是我的控制器:

$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

任何答案?

非常感谢......

2 个答案:

答案 0 :(得分:0)

if ($result > 10) 

$result资源本身,您必须从中获取数据。 $result本身并不是你想要的。从结果中获取必填字段。

例如

$row = $result->row();
if ($row->max_post > 10)

答案 1 :(得分:0)

if(mysql_num_rows($result)>10)
{

}

尝试使用此