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 10 of 10

Thread: Checkboxes?

  1. #1
    Regular Coder
    Join Date
    Sep 2009
    Location
    Calgary, Alberta
    Posts
    239
    Thanks
    47
    Thanked 3 Times in 3 Posts

    Checkboxes?

    I am looking at having these checkboxes send thier value to a data base..

    What is the best method?


    I have 90 or so check boxes with different values that need to be retrieved from the database at a time.. which would be the best method of

    1) adding to the database.. structure yet to be determined

    2) on edit of record placing them in or just updating the change? ..

    3) retrieval of all the checkboxes when needed?

    see the attached image of checkboxes. they have a value of 1 to 90


    Please try if you can to explain in noob terms as I am still new at this part.

    Thanks.

  • #2
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,456
    Thanks
    8
    Thanked 1,084 Times in 1,075 Posts
    I have a question about the checkboxes ...

    Example ..
    Is it possible for the user to check both the 3-door and the 5-door
    at the same time? Or will your script supposed to be a selection between
    the two. I have the same question for all other choices also.

    I'm thinking you need a chain-style selection to select one from each category?

    Maybe we need to know what your script (or website) is going to be used for?


    .

  • #3
    Regular Coder
    Join Date
    Sep 2009
    Location
    Calgary, Alberta
    Posts
    239
    Thanks
    47
    Thanked 3 Times in 3 Posts
    Hey mlseim,

    This is for a backend area of a car dealership website..

    This check box area Is to make it easier to add the options to the vehicles.. So it does not matter what the choice.. As long as it is in the database and can be pulled out for reference to the vehicle and can be changed on a whim.


    Currently I was thinking a array into the database but not sure what the structure should be for storing the options.

    I have the car in a different database and will reference the two with the vehicle stock number that I have in the vehicle DB. Just need t figure out these annoying checkboxes.

    Thanks..

  • #4
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,456
    Thanks
    8
    Thanked 1,084 Times in 1,075 Posts
    I'm really pondering this one ...

    The main point about how to handle the database tables would be the ability
    to add, delete, or modify the various options. That's going to be a big deal.
    You want this to be flexible enough for changes without modifying everything.

    So now, you're at the point of determining a way to accomplish a "normalized"
    database, and yet make this thing easy to manage. You should really hope now
    that other forum programmers offer some advice ... I believe we are all going to
    come-up with different ideas and opinions on this topic.

    One idea ...

    Give each group a category number, and each option within that group a sub-category number.

    So you have a table that contains the list of all categories and sub-categories.

    Table Name: itemList
    Row ID | category | subcategory | description | cost | availability | etc | etc

    12 | 2 | 3 | Antenna: Phone |
    13 | 2 | 4 | Antenna: Power Antenna |
    22 | 2 | 5 | Antenna: Window Antenna |
    124 | 22 | 1 | Tonneau: Hard |
    225 | 22 | 2 | Tonneau: Soft |

    Your rows are added in any order, each row getting a unique ID when the row is inserted.
    You can add more, delete them, modify them, change info, etc. and once the
    change is made, the list of checkboxes will change automatically because PHP
    is using this table to create your page of checkboxes. It loops by category and
    by sub-category.

    You have another table that adds a row for each item assigned to a VIN number.

    Table: vinList
    Row ID| VIN | category | subcategory | amount |

    532 | W454345J37789M234 | 2 | 4 |

    So that vehicle has a Antenna, Power Antenna.

    This table will get to be really huge. Maybe you could create a table
    for each VIN? The name of the table would be the VIN number?

    The queries would now be done by first searching for the VIN,
    then within that result, join the categories and subcategories of
    one table to the other so you can get a comprehensive result
    of the options for that VIN.

    The key point to all of this is the PHP script using the database to create your
    page of checkboxes. As it creates the actual HTML list, the value of each checkbox is
    the category|subcategory.

    <input type="checkbox" name="checks[]" value="22|1"> Tonneau: Hard
    <input type="checkbox" name="checks[]" value="22|2"> Tonneau: Soft

    When submitted, the PHP script processes the array called checks[] and
    knows which checkboxes were checked and knows which category and
    subcategory was checked for each one.

    That's my thinking anyhow ...

    Anyone else?



    .
    Last edited by mlseim; 01-02-2013 at 06:33 PM.

  • #5
    Regular Coder
    Join Date
    Sep 2009
    Location
    Calgary, Alberta
    Posts
    239
    Thanks
    47
    Thanked 3 Times in 3 Posts
    mlseim,


    Thanks for the post... wow..


    I will have to finish reading this one when I am at home...


    Thanks...

  • #6
    Regular Coder
    Join Date
    Sep 2009
    Location
    Calgary, Alberta
    Posts
    239
    Thanks
    47
    Thanked 3 Times in 3 Posts
    Hey mlseim,

    I thank you for you post.. I am how now wondering this.

    I have 90 checkboxes... I want either a yes or no or a 1 or 0 or a on and off..

    Which is the better to use?

    1 or 0

    Yes or No

    On and Off

    or even Checked or NotChecked?


    The reason I ask is this... could I do it this way?

    The DB
    PHP Code:
    options_id VIN op1 op2 op3 op4 op5 etc to op90 
    and have each checkbox with either the 1 or 0 or Yes and No.... etc..

    Each one of these records are removed after the vehicle has been sold.. and the record is deleted.. this associated record will go with it.?

    Can this way work?


    and if it can... should I run a different If statement to show the record.

    for example
    PHP Code:
    if ($row[op1]=='1') {
    echo 
    "14 Alloy Wheels";

    All down the list until done... or is there a shorter way?


    Sorry... for all the babble..


    Thanks again..


    Slayer.

  • #7
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,456
    Thanks
    8
    Thanked 1,084 Times in 1,075 Posts
    I guess you could do it that way.
    When a row is created, make all columns zero (0).
    For checkbox values, make them 1.

    You'll see the problem though ... the reason I gave my original answer ...
    You're going to have to hand-code 90 different checkboxes in your HTML
    form, and read those 90 checkboxes. If you decide to add an option, you'll
    have to edit your HTML form, your PHP script, and your database table.

    It doesn't matter what you make the column values ...
    It does matter how you develop the scheme for reading checkboxes.

  • #8
    Regular Coder
    Join Date
    Sep 2009
    Location
    Calgary, Alberta
    Posts
    239
    Thanks
    47
    Thanked 3 Times in 3 Posts
    is there a quicker way of doing this

    PHP Code:
    if ($row[op1]=='1') {
    echo 
    "14 Alloy Wheels"

    from $row[op1] to $row[op90]

    sure would make things easier.. any idea?

    Thanks, Slayer

  • #9
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,456
    Thanks
    8
    Thanked 1,084 Times in 1,075 Posts
    no, it doesn't work that way.

    Add a row for each item per VIN (like I described) and then
    delete all rows with the matching VIN when you're done with it.
    That will keep the table size manageable.

  • Users who have thanked mlseim for this post:

    SlayerACC (01-04-2013)

  • #10
    Regular Coder
    Join Date
    Sep 2009
    Location
    Calgary, Alberta
    Posts
    239
    Thanks
    47
    Thanked 3 Times in 3 Posts
    Thanks for your help.

    I have taken 4 hours or so to get the 90 checkboxes, the database all working together the way I needed to...

    Wow what a treat that was... not..


    Now I have another 110 or so to go for the other areas..


    Thanks again for everything.


    Slayer


  •  

    Posting Permissions

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