Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Handling product options

Status
Not open for further replies.

Bastien

Programmer
May 29, 2000
1,683
CA
HI All,

I am developing an application where each product may or may not have options (all data stored in DB). What is puzzling me is how to handle the options coming back from the clientside.

I have created the order/add to cart page where the user can see and choose the options associated with a particular product (have generated the options dynamically on each page based on product). I was planning to use checkboxes for each option. My dilema is that I am unsure as to how to read the options on the server and then pass them to the cart table/sales table. What I want to do is to place all the options in an array and write the entire array of options(csv) to a text field in the DB.

I just can't seem to figure out how to handle the dynamic number of checkboxes. Does any one have any ideas?

My other option would be to populate a select box with the options and let the user choose that way (using the MULTIPLE attribute to allow more than one choice). I would prefer to use checkboxes as the interface is easier for the user to understand.

If this is not clear, I can try to explain it again.

TIA Bastien

There are many ways to skin this cat,
but it still tastes like chicken
 
Read back a couple of pages, this was covered in good detail in the last week or so. ***************************************
Party on, dudes!
[cannon]
 
Do you have a thread number? Bastien

There are many ways to skin this cat,
but it still tastes like chicken
 
Hi Karver

The SELECT / OPTION I can do...I just was hesitant becuase I like the look of the CHeckboxes better...what I was interested in is the checkboxes....how do I handle the dynamic number of elements that may be generated?

Let me give a better example...

prod1 has 2 options
prod2 has 5 options
prod3 has 0 options

what I have is one page that diplays the product and the options...I could code to loop through the five options but since the client will have control over the number of options which may change in the future, How can I code to make it adaptable to more options (ie hardcoding the 5 options is not acceptable)?

TIA Bastien

There are many ways to skin this cat,
but it still tastes like chicken
 
This thread should cover most of it

thread434-251530 ***************************************
Party on, dudes!
[cannon]
 
would it not be fairly simple to just use a dynamic for loop?
use count() to find the length of the "$options" array and do something like:
if($options)
{
for($i=0;$i<count($options);$i++)
{
print &quot;<input type=radio name=$i>$options[$i]&quot;;
}
}
else
{
print &quot;there are no options for this product&quot;;
}

this would, if the $options array existed, run through a for loop, producing dynamically numberd radio boxes, which u could then relate to the option number. it would then print next to the radio button the contents of that option number in the $options slot, so if the first option was &quot;added 315mb ram&quot; you would get this html:

<input type=radio name=0>added 512mb ram

i've used this a few times in perl (and sometimes done it backwards too :p ) and it seems to be flawless.
Cheers. /Sib
programmer in the making
icq: 44167565
e-mail: siberdude@ntlworld.com
 
HI Sib

Yeah that is what I have to display the HTML but in check box format...the problem is how do I get a dynamic number of options back into the DB tables for the product being purchased?

How do I handle the submission to the server and the combining of the checkboxes into an array that will be variable in length?

TIA Bastien

There are many ways to skin this cat,
but it still tastes like chicken
 
Well, I've only ever used flat file databasing, so i never had this kind of problem. the datagbasing structue was always flexible enough to ahdnle variable data forms. /Sib
programmer in the making
icq: 44167565
e-mail: siberdude@ntlworld.com
 
What you need is a lesson of database.

You want to have some options in one order, so i suppose you have a table with the order info.
I suggest you to create another table with the options you are going to have in each order (all of them, for all orders)
then you create another table with this:
orders_options:
order_id
option_id

then you insert in this table ALL THE CHECKED options.

This is the best way to solve your problem. Forget that thing of the text field with HTML code. It's garbage and the most dificult thing to process. Anikin
Hugo Alexandre Dias
Web-Programmer
anikin_jedi@hotmail.com
 
Hi Anikin,

Got all that already...what I was missing was absurdly simple...i did not remember that checkboxes can be NAMED the same with different VALUES (ie the value of the option) then php automatically makes this an array by using the [] in the checkbox name (like optoins[])...then all I had to do on the page the form is submitted to I just implode the array, then I insert the array into a text field....

Thanks to all for your input... Bastien

There are many ways to skin this cat,
but it still tastes like chicken
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top