467,922 Members | 1,301 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,922 developers. It's quick & easy.

Whats the best way to do this?

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
submitted.

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:

Colours
-----------
Blue,black,green

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!

Thanks

Flic

Sep 11 '06 #1
  • viewed: 1165
Share:
3 Replies
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</OPTIONor 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.

Aaron

Flic wrote:
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
submitted.

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:

Colours
-----------
Blue,black,green

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!

Thanks

Flic
Sep 11 '06 #2

frothpoker wrote:
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.
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
entry?

Sep 11 '06 #3
Flic wrote:
frothpoker wrote:
>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.

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
entry?
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 <Selectload from $DB to form
$s =& $form->createElement('select','u_category','Category:' );
$s->loadQuery($db, $category_dropdown_select);
$form->addElement($s);

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

http://www.devarticles.com/c/a/Web-G...orm-Processing

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-)
Sep 11 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Eva | last post: by
3 posts views Thread by Kevin Steffer | last post: by
2 posts views Thread by SOR | last post: by
5 posts views Thread by Panama Red | last post: by
4 posts views Thread by David Lozzi | last post: by
16 posts views Thread by Brian Henry | last post: by
7 posts views Thread by Paulo | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.