在表字段中的字符串中检查值

时间:2015-08-13 17:34:35

标签: php mysql codeigniter

我有一个包含博客帖子的表格,我想根据谁查看哪篇文章来控制显示。我在db' post_seen'中添加了一个新表格字段。并希望附加“viewer_id”#39;到现场(例如:' user5,user2,user8')。我希望能够检查用户ID是否在post see字段中,以执行某些操作。

查询似乎没有起作用到目前为止我已经完成了这个

    public  function checkUnSeenPosts($myid){
              //select all posts where user_id not found in post_seen column
              $query = "SELECT * FROM mutamba_posts WHERE INSTR('post_seen',".$myid.") > 0";

                $sql = $this->db->query($query);
                if($sql->num_rows() > 0){
                    return true;
                }else{
                    return false;

                }


         }


  function markPostsAsSeen($user_id){
        //select all posts where user_id not found in post_seen column
        $query = "SELECT * FROM mutamba_posts WHERE INSTR('post_seen',".$user_id.")< 0";

        $sql = $this->db->query($query);
        if($sql->num_rows() > 0){

            foreach ($sql->result() as $r){

                        $data = array('post_seen' => $r->post_seen.','.$user_id); 
                        $this->db->update('mutamba_posts',$data);


            }
        }


    }

0 个答案:

没有答案