Whats the best way to do this?

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
Hi, I currently have a website that uses an option drop down box to
select different colours for an item before the form it is in is

This works fine but as I am trying to advance my skills I decided to
learn PHP to use with SQL which I already know. I have yet to start but
am thinking of how to go about it and looking at some example code. The
whole thing looks easier enough but I was wondering how these option
boxs would fit into it.

I'm thinking one way to possibly do it would be an array with all the
options in. However, would it be possible to have what should be the
contents of the array as part of the table? For eg something like:


And also would it be possible using these to change the price of an
item? That isn't so important now but may be useful in the future,
although I can make it work another way if need be.

Any help much appreciated!



Re: Whats the best way to do this?

PHP is a server side language so you would use it to replace hard coded
 <OPTION value = Blue>Blue</OPTION>
 <OPTION value = Green>Green</OPTION>
 <OPTION value = Black>Black</OPTION>

with colours from a database query or some other source.  The HTML page
you generate doesn't care if it was hard coded or built on the fly by
PSP / ASP or anything else.

As for changing the prices would be to either embed the price in the
code somewhere
 <OPTION value = Blue(14.99)>Blue</OPTION> or as a hidden field on the
form, containing an array of the data you need...

and use javascript to change a form field value client side, or to
resubmit the page and find the correct price for the item added.
Personally I'd resubmit coz lots of people have JS turned off and
otherwise they would be able to see the data in its raw form.


Flic wrote:
Quoted text here. Click to load it

Re: Whats the best way to do this?

frothpoker wrote:
Quoted text here. Click to load it

I know this much, my question was how? If each of the different item
had different colours how would it be best to populate the list?
Something like i++ would work on single rows, but what about a single

Re: Whats the best way to do this?

Flic wrote:
Quoted text here. Click to load it

If you do not mind you could use the PEAR package HTML_QuickForm. With  
this package I can load a dropdown, from a database table, in three  
statements. Example:

     // Add the <Select> load from $DB to form
     $s =& $form->createElement('select','u_category','Category:' );
     $s->loadQuery($db, $category_dropdown_select);

There is a excellent tutorial on using the HTML_QuickForm package here:


I have not look at HTML_QuickForm2 that is suppose to be a newer  
incarnation of HTML_QuickForm.

Thanks in Advance...
IchBin, Pocono Lake, Pa, USA              http://weconsultants.phpnet.us
'If there is one, Knowledge is the "Fountain of Youth"'
-William E. Taylor,  Regular Guy (1952-)

Site Timeline