Forums

PHP

This topic is locked

Criteria Field with more then one value

Posted 15 Aug 2002 16:37:51
1
has voted
15 Aug 2002 16:37:51 Pat Heuber posted:
I have received a Excel Spreadsheet as a basis for a e-commerce project. The spread sheet contains all the articles and criterias and IDs neccessary. It is pretty big (26.000 articles). The problem for me is the following: for example one criteria is the color of a shirt. Within the spreadshead there is a field info1 containing all possible colors seperated by comma in that one field. I would like to take over the spreadsheet the way it is as a mySQL Database. But how can I read out that field with the color information to show the possible values in a list/menu form field via php and simultaneously separate them again for the users choice.

Example:
ID=1
article=shirt
info5=(white, black,red, blue)
price=25.99

I like to avoid converting that spreadshead into 5 or 6 different tables only because the criterias do not contain one field for each color.



Replies

Replied 18 Aug 2002 15:17:50
18 Aug 2002 15:17:50 Tim Green replied:
Using your example your code might look something like this:-

<?php
$options = explode(",",$info5);
?>
<SELECT name="color">
<?php
for ($k=0; $k < count($options); $k++) {
?>
<option value="<?php echo $options[$k]; ?>"><?php echo $options[$k]; ?></option>
<?php
}
?>
</SELECT>


Basically this takes the comma-delimited values and turns them into an array. We cycle through each element of the array, with the code, and output each option individually. This is a technique that is often used, and hopefully with this code, you will be able to work with your information without having to restructure the database at all.

I hope it helps

Tim Green

Extension & PHP TalkZone Manager
<font size=1>-------------------------------------------
<i>Please read the Forum FAQ before posting
a question to this TalkZone.</i>
-------------------------------------------
www.UDzone.com : A dynamic Dreamweaver,
Ultradev and Fireworks site for developers
by developers.
-------------------------------------------</font id=size1>
Replied 19 Aug 2002 10:51:13
19 Aug 2002 10:51:13 Pat Heuber replied:
Fantastic ! I posted this question so many times and guess what, who finally gives me a hint ? Thank you again Tim, this will help me so much in order to keep the time plan. Will this work for values as well, that are seperated by a slash ? I have a field that works almost the same way, but it includes the lengths of field hockey sticks looking like this:

info4=(34"/36,5" the slash in this case seperates the two different sizes

what would I have to to with the quotes. Can I just use your sample code and exchange the comme with a slash ?



Reply to this topic