Welcome Guest, Not a member yet? Register   Sign In
Update multiple rows in a table
#6

[eluser]Mellis[/eluser]
Allright.
I'm going to suggest a way to make this work. This is just a suggestion. Anybody who has a better approach, is very welcome to correct me, I want to learn, but for now I would handle it like this.

I would update my model a bit:

I wouldn't hardcode the $_POST in insertlist()
Code:
function insertlist($values){
        $query = $this->db->insert('contacts',$_values);
        return $query;
        }

I would replace poplist() and compareID() with a function getcontacts or something simular
Code:
getcontacts($id = null)
{
  $this->db->orderby('id','DESC');
  //check for the id here (could be a single value or an array)
  //add the where clause if $id
  $return the result
  // this way you can use it to get all or some of the contacts
}


I would make a view to add / edit a single contact and a different view to edit multiple contacts.

In my controller i would have a method contact() and contacts()
something like this:
Code:
public function contact($id = null)
{

//set your validation rules
if($this->validation->run())
  {
  if($id){ // should contain check if its a real contact id & then you could update your contact information
  }elseif(!$id){ //insert your contact information}
  //if succesfull insert or update -> redirect or do whatever you want
}else{
// load your contact form here.
if($id) // get the contact information and pass it to the contact form as standard input (after submission form fields should use validation input as value.
}
}

btw i have an input helper (saw it on the forum around here somewhere) that checks if I have $this->validation->input_name. If I don't have that, it returns a standard input i passed throught in the controller


Messages In This Thread
Update multiple rows in a table - by El Forum - 08-19-2008, 01:41 AM
Update multiple rows in a table - by El Forum - 08-19-2008, 01:45 AM
Update multiple rows in a table - by El Forum - 08-19-2008, 01:56 AM
Update multiple rows in a table - by El Forum - 08-19-2008, 02:52 AM
Update multiple rows in a table - by El Forum - 08-19-2008, 03:21 AM
Update multiple rows in a table - by El Forum - 08-19-2008, 04:07 AM
Update multiple rows in a table - by El Forum - 08-19-2008, 04:32 AM
Update multiple rows in a table - by El Forum - 08-19-2008, 05:14 AM
Update multiple rows in a table - by El Forum - 08-19-2008, 07:31 AM
Update multiple rows in a table - by El Forum - 08-19-2008, 07:04 PM



Theme © iAndrew 2016 - Forum software by © MyBB