Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-01-2013, 10:54 PM   PM User | #1
SlayerACC
Regular Coder

 
Join Date: Sep 2009
Location: Calgary, Alberta
Posts: 222
Thanks: 45
Thanked 3 Times in 3 Posts
SlayerACC is an unknown quantity at this point
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.
SlayerACC is offline   Reply With Quote
Old 01-02-2013, 01:13 AM   PM User | #2
mlseim
Master Coder

 
mlseim's Avatar
 
Join Date: Jun 2003
Location: Cottage Grove, Minnesota
Posts: 9,045
Thanks: 8
Thanked 1,029 Times in 1,020 Posts
mlseim has a spectacular aura aboutmlseim has a spectacular aura aboutmlseim has a spectacular aura about
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?


.
mlseim is offline   Reply With Quote
Old 01-02-2013, 01:43 AM   PM User | #3
SlayerACC
Regular Coder

 
Join Date: Sep 2009
Location: Calgary, Alberta
Posts: 222
Thanks: 45
Thanked 3 Times in 3 Posts
SlayerACC is an unknown quantity at this point
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..
SlayerACC is offline   Reply With Quote
Old 01-02-2013, 06:31 PM   PM User | #4
mlseim
Master Coder

 
mlseim's Avatar
 
Join Date: Jun 2003
Location: Cottage Grove, Minnesota
Posts: 9,045
Thanks: 8
Thanked 1,029 Times in 1,020 Posts
mlseim has a spectacular aura aboutmlseim has a spectacular aura aboutmlseim has a spectacular aura about
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..
mlseim is offline   Reply With Quote
Old 01-02-2013, 09:22 PM   PM User | #5
SlayerACC
Regular Coder

 
Join Date: Sep 2009
Location: Calgary, Alberta
Posts: 222
Thanks: 45
Thanked 3 Times in 3 Posts
SlayerACC is an unknown quantity at this point
mlseim,


Thanks for the post... wow..


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


Thanks...
SlayerACC is offline   Reply With Quote
Old 01-03-2013, 03:49 AM   PM User | #6
SlayerACC
Regular Coder

 
Join Date: Sep 2009
Location: Calgary, Alberta
Posts: 222
Thanks: 45
Thanked 3 Times in 3 Posts
SlayerACC is an unknown quantity at this point
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.
SlayerACC is offline   Reply With Quote
Old 01-03-2013, 01:05 PM   PM User | #7
mlseim
Master Coder

 
mlseim's Avatar
 
Join Date: Jun 2003
Location: Cottage Grove, Minnesota
Posts: 9,045
Thanks: 8
Thanked 1,029 Times in 1,020 Posts
mlseim has a spectacular aura aboutmlseim has a spectacular aura aboutmlseim has a spectacular aura about
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.
mlseim is offline   Reply With Quote
Old 01-03-2013, 07:44 PM   PM User | #8
SlayerACC
Regular Coder

 
Join Date: Sep 2009
Location: Calgary, Alberta
Posts: 222
Thanks: 45
Thanked 3 Times in 3 Posts
SlayerACC is an unknown quantity at this point
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
SlayerACC is offline   Reply With Quote
Old 01-03-2013, 10:34 PM   PM User | #9
mlseim
Master Coder

 
mlseim's Avatar
 
Join Date: Jun 2003
Location: Cottage Grove, Minnesota
Posts: 9,045
Thanks: 8
Thanked 1,029 Times in 1,020 Posts
mlseim has a spectacular aura aboutmlseim has a spectacular aura aboutmlseim has a spectacular aura about
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.
mlseim is offline   Reply With Quote
Users who have thanked mlseim for this post:
SlayerACC (01-04-2013)
Old 01-04-2013, 03:52 AM   PM User | #10
SlayerACC
Regular Coder

 
Join Date: Sep 2009
Location: Calgary, Alberta
Posts: 222
Thanks: 45
Thanked 3 Times in 3 Posts
SlayerACC is an unknown quantity at this point
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
SlayerACC is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 11:38 PM.


Advertisement
Log in to turn off these ads.