• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Resolved] 2 tables in one form

#1
[eluser]Yash[/eluser]
I want to update 2 tables using a single form.How can I do this?

like I want to distribute information in 2 tables using single form.

#2
[eluser]xwero[/eluser]
Forms aren't coupled with database tables. Forms just gather information from the user and you have to program how that information gets stored.
view file
Code:
<form>
<input type="text" name="field1">
<input type="text" name="field2">
<input type="submit" value="send">
</form>
controller
Code:
if(isset($_POST))
{
    // validation
    $this->load->model('Somemodel','',true);
    $this->Somemodel->insert($_POST);
}
model
Code:
function insert($post)
{
    $this->db->query('insert into table1 (field1) values (?)',array($post['field1']));
    $this->db->query('insert into table2 (field1) values (?)',array($post['field2']));
}

This is example code so don't use this for production sites. I hope this gets you on your way.

#3
[eluser]Yash[/eluser]
u rocks...

Is it necessary to use model?.What is that some model.I'm new to this CI.

http://aquireknowledge.com/phpframework/...nsertstory

Here I want to insert top 2 fields in one table and other in second.I'm using CI validation class.

Thank you for fast reply.

#4
[eluser]xwero[/eluser]
Models are where you store all the functions that have to do with database manipulation. It is a part of the MVC pattern which is used by CI to create easier to maintain sites. CI does other things too but this is the heart of the framework.

The creation of models isn't much different that creating a controller you just extend the Model class instead of the Controller class.

#5
[eluser]Yash[/eluser]
now I got it..Thank you

I like model approach.It help me creating what I want.


U rocks man


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.