喂,

我写了一个查询,我想显示当前用户未关注的用户列表,但我只显示2条记录,而当我删除限制时,它显示了除我关注的用户之外的所有用户很好,但是我不知道为什么我将限制设为5时只显示2个用户,所以前3个用户没有显示是因为它是我遵循的脚本,所以我无法正确解释但是,我感谢您的评论,因此我可以做出更多相应的解释

<?php
$sql = $this->db->limit(5);
$sql = $this->db->get('users');
foreach($sql->result() as $data):
$sql1 = $this->db->get_where('followers', array('user_id' => $data->id));
$sql2 = $this->db->get_where('followers', array('user_id' => $data->id, 'follower_id' => $user_id));
if($sql2->num_rows() != 0):
echo $data->username;
endif;
endforeach;
?>


表结构关注者

id(int)
user_id(int)
follower_id(int)


表结构用户

id(int)
username(varchar)
email(varchar)
password(varchar)

最佳答案

<?php
    $this->db->start_cache();
    $sql = $this->db->limit(5);
    $this->db->stop_cache();
    $sql = $this->db->get('users');
    $this->db->flush_cache();

    foreach($sql->result() as $data):
    $this->db->start_cache();
    $sql1 = $this->db->get_where('followers', array('user_id' => $data->id));
    $this->db->flush_cache();

    $this->db->start_cache();
    $sql2 = $this->db->get_where('followers', array('user_id' => $data->id, 'follower_id' => $user_id));
    $this->db->flush_cache();

    if($sql2->num_rows() != 0):
    echo $data->username;
    endif;
    endforeach;
?>

09-08 06:50