Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Apr 2009
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Form variables in php that change need to concatonate.

    Ok ill see if i can post this since its a VERY in-depth bunch of code im writing. I really just need to get the basic idea of what my steps would be and the logic of the total process. Also for shortness sake im going to abbreviate Concatonate to concat

    I am building an ads listing site. This site has obviously MANY different category's and in those are subcategory's. One of the things im implementing is the ability to have different options for the different subcategory that is chosen. Kind of like eBay and how you get different options when you post a digital camera as opposed to a piece of furniture; you get the idea.

    My current process is fairly simple. Once the main page loads (post.php) it auto populates the boxes (country, region, city, category and subcategory) via JS back to the MySQL DB via a logic script(post_logic.php). Then the user is on the hook for filling in the information into the correct <textbox>. I then have it POST it to the next screen (postrev.php); This is where the problems begin.

    Since every subcategory has different options then every option has a different ID in the DB and each Option has the subcategory's ID so i have a way to have a relation between the two. Here is a layout of my table.

    I hope this is readable.
    Code:
    optID |	cat_id | sub_cat_id | sub_option | optOrder | TIMESTAMP
    1       |    4    |       26      |  Location    |      1     |  2009-04-16 15:49:09
    2       |    4    |       26      |  Time        |      2     |  2009-04-16 15:49:09
    3       |    4    |       26      |  Map Link    |      3     |	 2009-04-16 15:49:09
    When i get to the POSTREV.php page where it inputs the data into the DB i have multiple IDs that change ALL the time depending on what subcategory the user(s) pick. What id like to do is dump all the sub_option and their <textbox> values into a concat'd field in my DB called OPTIONS for that ad listing where i can explode them later having some sort of comma in between all the sets of values. For example, using the DB example up top id like to have
    Code:
    Location: New York, Time: 8am, Map Link: someURL.
    How do i go about doing this. I feel like i would need to concat it into a single variable on the main form page then send it over to the DB input page maybe using OnClick function??? but im not REALLY savy on JS and how it all works so i wasnt able to find what i needed.

    I know this is LLOOONNG and drawn out, but im at my wits end and this is one of the main things stopping me from launching the site and ive been screwin with this for the past 2-3 weeks with no solution.

    Thanks in advance and if i missed something or i need to explain something further please let me know.

    Thanks!
    Last edited by boniggy; 04-30-2009 at 07:04 PM.

  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    My suggestion would be to normalize your database. This means instead of using one table to store all of the relationships between category, subcategory, and sub-option, you use multiple tables. One (or several) to represent each object (cat, subcat, or sub-opt) and its attributes (description, etc) and another (or several others) to define the relationships between the objects.

    You should read this article on how to set up a simple parent-child relationship:

    http://www.guelphdad.wefixtech.co.uk...atsubcat.shtml

    (Thanks to Guelphdad for writing the article)

    You'll then want to re-shape the example in that article to fit your needs. For example, if the attributes of your Categories are pretty much the same as the attributes of your sub-categories, you may want to put both cats and subcats in one table. You would then differentiate them simply by the definition of their relationships with other cats and subcats.

  • Users who have thanked Fumigator for this post:

    boniggy (04-30-2009)

  • #3
    New to the CF scene
    Join Date
    Apr 2009
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts
    ok i THINK i understand what you're saying... do you mean i should have multiple tables for everything? if thats the case then i do already have that setup.

    These are my tables.

    Code:
    category_main
    CatID | Main_Cat
    1       | For Sale
    2       | Events
    
    category_sub
    SubID | MainID | Sub_Cat
    1       | 1        |  Automobiles
    2       | 1        |  Boats
    3       | 2        | Concerts
    
    category_options
    optID | sub_cat_id | sub_option
    1      | 1              | Color:
    2      | 1              | Make:
    3      | 1              | Style:
    4      | 2              | Color:
    5      | 2              | Engine Type:
    6      | 3              | Location:
    6      | 3              | Time:
    etc....
    I am then able to do the relationships as i need them throughout the DB. My problem is when i have multiple option IDs that change. How do i write the code to compensate for the changing optID's whenever someone picks a different subcategory.

    Thanks for the reply so far. I hope im being clear enough.
    Last edited by boniggy; 04-30-2009 at 07:58 PM.

  • #4
    New to the CF scene
    Join Date
    Apr 2009
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Holy Crap! i think i figured it out! Thanks for the link... basically is what my logic path is NOW... please correct me if im off on this but i think it'll work.

    In the above post you can see my table layout and how the IDs will/can relate to each of the different tables.

    I've just added table called category_opt_values and it looks like this
    Code:
    ID  |  adID  |  adOption  |  optValue
    So now to add to the above posted table layout.. it looks like this.

    Code:
    category_main
    CatID | Main_Cat
    1       | For Sale
    2       | Events
    
    category_sub
    SubID | MainID | Sub_Cat
    1       | 1        |  Automobiles
    2       | 1        |  Boats
    3       | 2        | Concerts
    
    category_options
    optID | sub_cat_id | sub_option
    1      | 1              | Color:
    2      | 1              | Make:
    3      | 1              | Style:
    4      | 2              | Color:
    5      | 2              | Engine Type:
    6      | 3              | Location:
    7      | 3              | Time:
    etc....
    
    category_opt_values
    ID  |  adID  |  adOption  |  optValue  
    1  |  51324  | Color:   |  Blue
    2  |  51324  | Make:    |  Honda
    3  |  51324  | Style:   |  4 Door
    etc...
    As long as i pull up the ad's ID which in this case is 51324 then it'll list all the options and its value..... !!!!!!!!!!!!!!!

    I seriously think this will work.. Now i just need to pull all the multiple variables into an array and dump them into the DB.

    thanks for the link and suggesting i look into the normalization....
    Last edited by boniggy; 04-30-2009 at 08:42 PM.


  •  

    Posting Permissions

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