Page 1 of 6 123 ... LastLast
Results 1 to 10 of 58

Thread: In this thread we will discuss CodeIgniter!

  1. #1
    Join Date
    Feb 2003
    Posts
    3,184
    Rep Power
    0

    Default In this thread we will discuss CodeIgniter!

    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.

  2. #2
    Join Date
    Sep 2004
    Posts
    356
    Rep Power
    0

    Default

    it handles it quite well. You should check out there forum they have a very active one.

  3. #3
    Join Date
    Feb 2003
    Posts
    3,184
    Rep Power
    0

    Default

    Quote Originally Posted by MadHacker View Post
    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.

  4. #4
    Join Date
    Sep 2004
    Posts
    356
    Rep Power
    0

    Default

    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)

    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);

    }
    ?>
    PS: OWEN i hate you for drawing me out... hate long post ^_^

  5. #5
    Join Date
    Feb 2003
    Posts
    3,184
    Rep Power
    0

    Default

    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?

  6. #6
    Join Date
    Sep 2004
    Posts
    356
    Rep Power
    0

    Default

    Quote Originally Posted by owen View Post
    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?
    SMH yes OWEN you can.

    They even have a form validation function built in

  7. #7
    Join Date
    Jun 2008
    Posts
    74
    Rep Power
    0

    Default

    Quote Originally Posted by MadHacker View Post
    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)

    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);

    }
    ?>
    PS: OWEN i hate you for drawing me out... hate long post ^_^
    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?

  8. #8
    Join Date
    Sep 2004
    Posts
    356
    Rep Power
    0

    Default

    Quote Originally Posted by jayrulez View Post
    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?
    PHP 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);


    ?>
    Did this help

  9. #9
    Join Date
    Jun 2008
    Posts
    74
    Rep Power
    0

    Default

    not really. but never mind.

  10. #10
    Join Date
    Sep 2004
    Posts
    356
    Rep Power
    0

    Default

    Quote Originally Posted by jayrulez View Post
    not really. but never mind.
    What about the example did you not understand let me see how best i can simplify it for you

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •