#1
  1. A Change of Season
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2004
    Location
    Next Door
    Posts
    2,689
    Rep Power
    171

    UPDATE patch situation


    Hi;
    Maybe I'm too tired to come up with a solution! But how can I update multiple textboxes with 1 click? The form looks like this:
    PHP Code:
    <?php 
            
    foreach($categories as $val=>$row)
                {
                    echo 
    "<input name=\"sub_cats[]\" type = \"text\" value = \"".$row['title']."\">";
                    echo 
    "<br />";
                }
            
    ?>
    Thanks
  2. #2
  3. Jealous Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,303
    Rep Power
    9400
  4. #3
  5. A Change of Season
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2004
    Location
    Next Door
    Posts
    2,689
    Rep Power
    171
    Originally Posted by requinix
    "Update"?
    Hello how are you?

    I mean UPDATE BATCH. Not Patch. Imagine a form with 300 input type text. They each are titles of blog entries in the database. Some have spelling errors, need to fix them all with one click.
    Need to create an array and send it to the database so it updates all the values:
    PHP Code:
    $data = array(
       array(
          
    'title' => 'My title' ,
          
    'name' => 'My Name 2' ,
          
    'date' => 'My date 2'
       
    ),
       array(
          
    'title' => 'Another title' ,
          
    'name' => 'Another Name 2' ,
          
    'date' => 'Another date 2'
       
    )
    );

    $this->db->update_batch('mytable'$data'title');

    // Produces:
    // UPDATE `mytable` SET `name` = CASE
    // WHEN `title` = 'My title' THEN 'My Name 2'
    // WHEN `title` = 'Another title' THEN 'Another Name 2'
    // ELSE `name` END,
    // `date` = CASE
    // WHEN `title` = 'My title' THEN 'My date 2'
    // WHEN `title` = 'Another title' THEN 'Another date 2'
    // ELSE `date` END
    // WHERE `title` IN ('My title','Another title') 
  6. #4
  7. A Change of Season
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2004
    Location
    Next Door
    Posts
    2,689
    Rep Power
    171
    Doesn't matter I did it.
    PHP Code:
    foreach($categories as $val=>$row)
        {
            echo 
    "<input name=\"sub_cats_id[]\" type = \"hidden\" value = \"".$row['id']."\">";
            echo 
    "<input name=\"sub_cats[]\" type = \"text\" value = \"".$row['title']."\">";
            echo 
    "<br />";
        } 
    PHP Code:
    public function do_edit()
        {
            
    $this->load->model('model_sa');
            
    $this->texts=$this->input->post('sub_cats_id');
            
    $this->sub_cats=$this->input->post('sub_cats');
            foreach(
    $this->input->post('sub_cats_id') as $count => $row)
                {
                    
    $this->posted_data[] = array('id'=>$row'title'=>$this->sub_cats[$count]);
                }
            
    $this->db->update_batch('systematic_attraction_sub_categories'$this->posted_data'id'); 
            
    $this->output->enable_profiler(TRUE);
        } 
    Thank you.
    ---------
    EDIT: Arrays are INSANE!

IMN logo majestic logo threadwatch logo seochat tools logo