Update multiple users at once? - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Update multiple users at once? (/showthread.php?tid=49239) |
Update multiple users at once? - El Forum - 02-12-2012 [eluser]codejack[/eluser] Hello. On my site, users can create teams (clans) and invite other users to join them. I'm working on a page at the moment where team leaders can edit the "ranks" of each user in the team. These options are Founder, Captain, Member, Inactive and Kick (which will remove the user from the team altogether). I've included a quick screenshot of how the page looks to help explain what I'm hoping to achieve. http://cl.ly/E9Gb So team leaders can go through and change the rank of each user and then hit update. What would be the best way to go about this? Here are some extracts from my code at present: CONTROLLER: Code: if ($this->input->post('update_roster')) MODEL: Code: public function update_roster($clan_id, $user_id, $rank) VIEW: Code: <h3>Roster</h3> Hopefully that all makes sense. I'm new to PHP/CI and I could really use some guidance on this! Thanks. Update multiple users at once? - El Forum - 02-13-2012 [eluser]elverion[/eluser] I'm not sure, but I think you can set the name of your dropdown to 'member_rank[]', which would then cause $this->input->post('member_rank') to be an array. That'll make it easy to run a for-loop to update each user. Additionally, if you think you're going to have a lot of members being updated at once and want to limit your SQL queries, you should separate the users into different arrays. Each array will be a list of user IDs for each group, so one array for Founder, one for Captain, and so on. Use this in your query: Code: $this->db->where_in('id', $captains); This would restrict your query count to the number of different ranks you have (~4), rather than running potentially hundreds of queries. |