duanpin5168 2017-03-21 11:22
浏览 21
已采纳

如果有一些依赖性,将记录添加到codeigniter中的列

I am having a post that user can send to 'another profile' on site, but before posting it will be added to 'some another profile'of other 'random users' and he must approve this post. 'Random users' will receive this submit for approval only if they already follows this 'another profile'. So, my question is:

how to check 'random users' follows 'some another profile' to get new requests for approve?

what I have tried this:

another_profile follows table (profile_follows):

profile_id | who_follow_id   
21           5

post that user submit for approve ( posts_for_approve ):

for_whom_id | submit_text | submit_author_id | post_id
21            some text     5                  2

users table ( users ):

user_id
5

and table with users that can approve ( users_can_approve ):

post_id | user_id
2         5

in my posts_model I'm getting all users:

function get_all_users()
{
    $this->db->select('user_id');
    $this->db->order_by('rand()');
    $query = $this->db->get('users');
    return $query->result_array();
}

in my controller I'm getting all users which will receive posts for approve:

$all_users = $this->stories_model->get_all_users();
 foreach ($all_users as $key) {
  $send_approve['post_id'] = $edit;
  $send_approve['user_id'] = '';
  $this->db->insert('contribute_moderators', $send_approve);
 }  

So this works, but in my code ALL site users will receive post for approve, but my need is to check users follows 'profile_id', to receive this post for approval. Thanks!

  • 写回答

1条回答 默认 最新

  • duanbenzan4050 2017-03-21 13:43
    关注

    Naturally your get_all_users() function gets all the users, which you don't want. You didn't answer my first question of the comment, but I' pretty sure you don't really want results from the users table anyway, you want the user_id from the profile_follows table. I'd rename it get_all_followers() and do something like this:

    //Note I'm passing the $profile_id to this function, which I assume you have access to
    function get_all_followers($profile_id)
    {
        $this->db->select('user_id');
        $this->db->order_by('rand()');
        $this->db->where('profile_id' = $profile_id);
        $query = $this->db->get('profile_follows');
        return $query->result_array;
    }
    

    Controller:

    $all_followers = $this->stories_model->get_all_followers($profile_id);
    foreach ($all_users as $key) {
      $send_approve['post_id'] = $edit;
      $send_approve['user_id'] = $key;  //your answer isn't clear to me, but I think this is where you need your follower user_id
      $this->db->insert('contribute_moderators', $send_approve);
    }  
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
  • ¥100 连续两帧图像高速减法
  • ¥15 如何绘制动力学系统的相图