maintaining relation while POSTing and while fetching.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rpnew
    New Member
    • Aug 2007
    • 189

    maintaining relation while POSTing and while fetching.

    Hello friends....
    I'm developing one project in PHP-MySql on FC4.....
    I'm facing a problem here at one place. Let me describe it....

    I've one page in php on which i'm generating a table containing checkboxes for option. These options have suboptions. User need to chose these options and suboptions. with suboption they are getting textboxes in which they can enter values for suboptons. When they submit the form i need to get all these data and accordingly store them into the database.
    Now problem comes because all these checkboxes and textboxes are generated dynamically meaning through values in database. So i've made an arrays for all these so that i can get the values of selected checkboxes and textboxes. So the problem is on the second page i cant determine which suboption and textbox value goes to which option means relation is broken i need to maintain this relation so that i can store these values in database maintaining foreign key..

    Now let me describe my database a bit so that if you have any other option then this you can suggest me.

    In database i've four tables say table1,table2,t able3 and table4.

    Table1 contains name of OPTION and NUMBER of SUBOPTION it has.
    Table2 contains name of SUBOPTIONS and OPTIONS they belongs(foreign key)

    Table3 is similar to Table1 and Table4 is similar to Table2(with one field added which will store the value of SUBOPTION coming through TEXTBOXES which user is providing at runtime.)

    So what i'm doing is getting the OPTIONS and SUBOPTIONS values from Table1 and 2 respectively and generating form. So when user submits the form i want to store these values into Table3 and 4 respectively.

    I told you what i'm doing. so if you can help with that its good and if you have any other idea with GUI as well let me know.
  • code green
    Recognized Expert Top Contributor
    • Mar 2007
    • 1726

    #2
    This is a plan, not a problem.
    I have to guess your problem is you don't know how to read form values.
    Well you use the $_POST array to extract data from a form

    Comment

    • rpnew
      New Member
      • Aug 2007
      • 189

      #3
      Originally posted by code green
      This is a plan, not a problem.
      I have to guess your problem is you don't know how to read form values.
      Well you use the $_POST array to extract data from a form

      Yes you are right that its a plan and
      you are wrong a bit that i dont know how to read form values...
      well nope..
      i know how to use $_POST or $_GET i'm doing that also but my problem is on the second page i'm getting all the values through three different arrays.. and i cant determine relationship between them so that while inserting into the table i can maintain foreign key relation...
      And i'm sending and receiving this values as Arrays because all these CHECKBOXES and TEXTBOXES are generated through code according to database values so they'll have same name so to receive all the checked values i've to use Arrays.......

      Well if you have any other way to do this let me know.. that will be very helpful

      Regards,
      RP

      Comment

      • rpnew
        New Member
        • Aug 2007
        • 189

        #4
        hello friends please help.. im stuck here at this place very badly...


        RP

        Comment

        • pbmods
          Recognized Expert Expert
          • Apr 2007
          • 5821

          #5
          Heya, RP.

          What do you want your code to do? Give an example.
          What is your code doing that you don't want it to do? Give an example.
          What is your code *not* doing that it is supposed to? Give an example.

          Comment

          • Atli
            Recognized Expert Expert
            • Nov 2006
            • 5062

            #6
            Hi.

            It would also help if you posted the code that generates the form on the first page.

            Comment

            • rpnew
              New Member
              • Aug 2007
              • 189

              #7
              Originally posted by pbmods
              Heya, RP.

              What do you want your code to do? Give an example.
              What is your code doing that you don't want it to do? Give an example.
              What is your code *not* doing that it is supposed to? Give an example.

              What do i've in database?

              As i told you earlier i've total of 4 tables......... ......
              say in table1 two columns are there name and noofvariable
              table two has name(foreign key to table1), variablename

              table3 is same as table1
              table4 is same as table2 with one column added that is variablevalue.. ....


              now what i'm doing?


              from table1 and table2 i'm generating one form which contains checkboxes and textboxes......
              like checkboxes for "name" its respective "variablename"( variables) and textboxes for these "variablena me" so that user can put values in that.....

              what i want.... when user submits i want... whatever the name and variable checked store them to table3 and table4 accordingly.... . also if user have provided values in textbox store them into table4......... ..

              problem i'm facing...

              As all these fields are generated dynamically means through code.... so i cant provide different names to checkboxes....s o they are an array.... like one array for 'name' checkbox one for 'variablename' checkbox and one for 'textfield'....

              well through this i can receive all the checked variables and textvalues entered on second page but on second page i cant determine which 'variablename' goes to which 'name'.....

              Regarding code
              well on first page i'm simply using while loop to generate the form according to database and on second to get the values i'm using foreach loop to access arrays.... so even i want to know that if there is another way to access the array...
              i've tried many things so i dont have a exact code now......and frankly i dont have any idea if at all this can be done as on second page you dont which variables are coming and how many(if using different names for all) as there can be as many as 100.... depending upon users selection......

              Comment

              • code green
                Recognized Expert Top Contributor
                • Mar 2007
                • 1726

                #8
                As all these fields are generated dynamically means through code.... so i cant provide different names to checkboxes
                If the checkboxes are generated within a loop [PHP]for($c=0; etc...)[/PHP]Then you can create a name for the checbox dynamically
                [PHP]echo '<input type="checkbox" name="mybox'.$c .'"id="'.$c.'"> Choice '.$c;[/PHP] If this idea does not suit then it is possible to send an array as a url variable.
                It needs to be declared as such in HTML.
                Can't remember how but it is simple

                Comment

                • rpnew
                  New Member
                  • Aug 2007
                  • 189

                  #9
                  Originally posted by code green
                  If the checkboxes are generated within a loop [PHP]for($c=0; etc...)[/PHP]Then you can create a name for the checbox dynamically
                  [PHP]echo '<input type="checkbox" name="mybox'.$c .'"id="'.$c.'"> Choice '.$c;[/PHP] If this idea does not suit then it is possible to send an array as a url variable.
                  It needs to be declared as such in HTML.
                  Can't remember how but it is simple
                  well yes i'm doing that... but my problem is to maintain relation between two arrays to store it into the tables..

                  however.. dont worry.. i've solved my problem at last.....

                  thanks for the reply.....

                  RP

                  Comment

                  • code green
                    Recognized Expert Top Contributor
                    • Mar 2007
                    • 1726

                    #10
                    Glad you solved your problem.
                    but my problem is to maintain relation between two arrays to store it into the tables..
                    What about a 2d array?

                    Comment

                    • rpnew
                      New Member
                      • Aug 2007
                      • 189

                      #11
                      Originally posted by code green
                      Glad you solved your problem.
                      What about a 2d array?
                      Well i've three arrays actually to manage.. to maintain their relation what i've done is....
                      The first one is aa array which contains values of CHECKBOXES..
                      The second one is also an array of CHECKBOXES(valu es of checkboxes)
                      The third is an array of TEXTBOXES..

                      Now i've given the name of the TEXTBOXES as content(value) of the second array(CHECKBOXE ) and For name of the Second array i've taken content(value) of the first array(CHECKBOX) ... and passed the first array across the pages....

                      So on the second page i'm already getting first array.. to get value of second array i'm using first array value and to get the third one i'm using value of the second array.. in that way by passing only one array i can access all three arrays... and relation is also maintained..

                      RP

                      Comment

                      • code green
                        Recognized Expert Top Contributor
                        • Mar 2007
                        • 1726

                        #12
                        You could possibly improve this by using an associative aray and naming the keys the same as checkbox/textbox name

                        Comment

                        • pbmods
                          Recognized Expert Expert
                          • Apr 2007
                          • 5821

                          #13
                          Heya, RP.

                          You may find this document of some interest.

                          Comment

                          • rpnew
                            New Member
                            • Aug 2007
                            • 189

                            #14
                            Originally posted by code green
                            You could possibly improve this by using an associative aray and naming the keys the same as checkbox/textbox name

                            hi......
                            well thanks for your suggestion..... but i dont know how to use associative array so if you can give me some information it will be useful....howev er i'll also try to search it on net..

                            Thanks,
                            RP

                            Comment

                            • rpnew
                              New Member
                              • Aug 2007
                              • 189

                              #15
                              Originally posted by pbmods
                              Heya, RP.

                              You may find this document of some interest.

                              Thanks to you as well..

                              RP

                              Comment

                              Working...