At 3:24 PM -0700 2/3/01, Gerry wrote:
>Hello:
>
>I'm trying to create dinamic color SELECT lists with php. I have my
>database set up as follows:
>
>Paint = good
>bucket = good
>weight = 100kg
>Colors = green, blue, red
>
>and here is my php:
>
>while ($row = mysql_fetch_array($sql_result)) {
>echo"<tr><td>";
>echo $row["paint"];
>echo"</td><td>";
>echo $row["bucket"];
>echo"</td><td>";
>echo"<form action=\"http://www.\" method=\"POST\">";

Replace this line:

>$Color  = $row["Color"];

with this:

$option = '';
$ColorArray = split(',' $row['Colors']);
while (list(, $Color) = each($ColorArray)) {
# yes, the comma in the list() should be there!

>if ($Color == $Color) {
>$option .= "<OPTION value=\"$Color\" selected>$Color</OPTION>";
>} else {
>$option .= "<OPTION value=\"$Color\">$Color</OPTION>";
>}

and add this here:

}


>echo"<select name=\"Colors\">";
>echo "$option";
>echo"</select>";

For more information, see

        http://www.php.net/split

Oh - and just in case the 'Colors' column is empty, you might want to 
do the while statement like -

while (is_array($ColorArray) && (list(, $Color) = each($ColorArray))) {

- since split() won't return an array if there's nothing to split.

        - steve


>
>as you can see I end up with a select menu with this "green, blue, red"
>as the only option.
>
>is there a way I can tell php3 to break it down at "," so I can actually
>have a drop down menu        
>
>Thanks ahead:
>Gerry Figueroa
>----------------------------------
>Modern Confucius:
>Man who run in front of car get tired.
>----------------------------------
>

-- 
+--- "They've got a cherry pie there, that'll kill ya" ------------------+
| Steve Edberg                           University of California, Davis |
| [EMAIL PROTECTED]                               Computer Consultant |
| http://aesric.ucdavis.edu/                  http://pgfsun.ucdavis.edu/ |
+-------------------------------------- FBI Special Agent Dale Cooper ---+

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to