Welcome Guest, Not a member yet? Register   Sign In
trying to updating multiple records with checkboxes but nothing updates
#5

[eluser]umefarooq[/eluser]
well i have another solution if you like it will help you more fast, right now its updating all you records for approved and unapproved. here is my solution

just pass id to checkbox array value not as Associative array here is the code for solution

HTML
Code:
<form action="blog/admin/action">
     <input type="checkbox" name="approved[]" value="1" />
     <input type="checkbox" name="approved[]" value="2" />
     <input type="checkbox" name="approved[]" value="3" />
     <input type="submit" name="submit" value="approve" />
     <input type="submit" name="submit" value="unapprove" />
     </form>

controller
Code:
function action(){
    $task = $this->input->get_post('submit');
    switch($task){
     case 'approve':
       $this->approve(1);
     break;
     case 'unapprove':
        $this->approve(0);
     break;
   }
}

  function approve($approve = 1){
    $ids = $this->input->get_post(approved);
    if(!empty($ids)){
         foreach($ids as $id){
          $vanity_url->where('id',$id)->get();
          $vanity_url->approved = $approve;
          $vanity_url->save();
      }
    }
     redirect('anywhere');
  }

you can see i have use submit button with same name but value is different it will submit value of that button which we press, and always get the ids of checked boxes and update only specific record not the whole list of records


Messages In This Thread
trying to updating multiple records with checkboxes but nothing updates - by El Forum - 04-06-2011, 12:12 AM



Theme © iAndrew 2016 - Forum software by © MyBB