And by discuss I mean we will ask @MadHacker (being using it for while now) to speak strongly on it while we ask him questions. Feel free to jump him if you like.
So Mad, how does it handle multiple table relationships in a single form?
And by discuss I mean we will ask @MadHacker (being using it for while now) to speak strongly on it while we ask him questions. Feel free to jump him if you like.
So Mad, how does it handle multiple table relationships in a single form?
Last edited by owen; Mar 31, 2011 at 10:12 AM.
Check out My Awesome Blog & News Jamaica
it handles it quite well. You should check out there forum they have a very active one.
That is the worst possible answer you could ever give. I hear COBOL handles multiple table well too. What I want to know is how much extra work would YOU have to do to create a form that has data from 2 or 3 different tables.
Based on this example it seem like you have to do a multi array thing;
http://codeigniter.com/forums/viewthread/55617/
It is one of those issues that popup during heavy coding of fancy forms. It doesn't always come up but sometimes you really want to do everything.
For example I have a registration form which has username and passwords but ask questions which are stored in another table. I could probably simply have 2 forms but most times you really want it to happen in 1 form.
Check out My Awesome Blog & News Jamaica
lol But i did said it can be done didnt I.
its quite easy all you need to do is capture the data and create the needed array then post them to the database example
lets say we have a form that capture students information and assign them to a class
StudentInformation:
Fname , Lname, TRN
ClassInformation:
ClassID , TeacherID , STUDENTTRN (fk)
PS: OWEN i hate you for drawing me out... hate long post ^_^PHP Code:
<?php
if(isset($_POST['submit'])){
$classid=$_POST['cid'];
$teacherid=$_POST['tid'];
$stuTrn=$_POST['stutrn'];
$lname=$_POST['lname'];
$fname=$_POST['cid'];
// Below we have the data being set for each field in Table 1 (student information)
$ValueSetOne = array('Fname'=>$lname, 'Lname'=>$lname, "TRN"=>$lname);
// Below we have the data being set for each field in Table 2 (Class Information)
$ValueSetTwo = array('TeacherID'=>$teacherid, 'ClassID'=>$classid, "STUDENTTRN"=>$stuTrn);
// Table one data being added
$this->db->insert('StudentInformation', $ValueSetOne);
// Table one data being added
$this->db->insert('ClassInformation', $ValueSetTwo);
}
?>
Suppose you have multiple classes that you want to validate and insert BEFORE you insert the student. And how easy is to build the front end user interface to handle it?
Check out My Awesome Blog & News Jamaica
how would you handle a situation where the pk from the owning side of the relationship is a serial or auto value? eg: storing a user and profile from the same form. tables: user(id, username, password), profile(user_id, first_name, last_name, gender, birth_date) and how would you validate this data?
Did this helpPHP Code:
<?php
// This example is under the assumption that we are using Autoincrement Value
// Below we add the user data
$data = array('username'=>'johndoe', 'password'=>md5('pass') );
$this->db->insert('user',$data);
// Below we capture the last insert id
$userid = $this->db->insert_id();
$data = array('user_id'=>$userid, 'first_name'=>'John' , 'last_name'=>'Doe', 'gender'=>'Male' , 'birth_date'=>'1984-01-01' );
$this->db->insert('user',$data);
?>
not really. but never mind.