如果有一些依赖性,将记录添加到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!

我有一个帖子,用户可以在网站上发送到“另一个个人资料”,但在发布之前会添加 对其他“随机用户”的“另一个档案”,他必须批准这篇文章。 “随机用户”只有在已经遵循此“其他个人资料”的情况下才会收到此提交以供审批。 所以,我的问题是: p>

如何检查“随机用户”跟随“另一个配置文件”以获得批准的新请求? p> blockquote>

我试过这个: p>

another_profile跟随表(profile_follows): p> profile_id | who_follow_id 21 5 code> pre>

发布该用户提交审批(posts_for_approve): p>

  for_whom_id |  submit_text |  submit_author_id |  post_id 
21 some text 5 2 
  code>  pre> 
 
 

users表(用户): p>

  user_id 
5 
   pre> 
 
 

以及可以批准用户的表(users_can_approve): p>

  post_id |  user_model中的user_id 
2 5 
  code>  pre> 
 
 

我收到了所有用户: p>

  function get_all_users()\  n {
 $ this-> db-> select('user_id'); 
 $ this-> db-> order_by('rand()'); 
 $ query = $ this->  db-> get('users'); 
返回$ query-> result_array(); 
} 
  code>  pre> 
 
 

在我的控制器中我得到了 所有将收到批准帖子的用户: p>

  $ 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('contribution_moderators',$ send_approve); 
}  
  code>  pre> 
 
 

这样可行,但在我的代码中,所有网站用户都会收到批准的帖子,但我需要检查用户是否有'profile_id',才能收到此帖子 需要批准。 谢谢! p> div>

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);
}