eagleweb Posted October 30, 2007 Share Posted October 30, 2007 I have a field in a db called 'option1' in which are three comma and space seperated colors; red, green, blue The person filling out the form has to choose a color. I can't figure out how to make the three colors appear in a drop down menu. $query3 = mysql_query("SELECT * FROM products WHERE prodlineid = '".$row2['id']."' ORDER BY ordered", $conn); $row3 = mysql_fetch_assoc($query3); $opt1 = $row3['option1']; if you echo $opt1 you will get red, green, blue I have exploded and imploded and can get various lists, but have not figured out how to get them into a select field in a form. <?php do { ?> <option value="<?php echo $opt1; ?>"><?php echo $opt1; ?></option> <?php } while ($row3 = mysql_fetch_assoc($query3)); ?> Quote Link to comment https://forums.phpfreaks.com/topic/75298-solved-select-box-from-array/ Share on other sites More sharing options...
toplay Posted October 30, 2007 Share Posted October 30, 2007 . . . $opt1 = $row3['option1']; $arrOptions = explode(',', $opt1); // echo select part for ($i = 0, $intCnt = count($arrOptions); $i < $intCnt; $i++) { $strOption = trim($arrOptions[$i]); echo "<option value=\"$strOption\">$strOption</option>"; } // echo /select part Quote Link to comment https://forums.phpfreaks.com/topic/75298-solved-select-box-from-array/#findComment-380833 Share on other sites More sharing options...
eagleweb Posted October 30, 2007 Author Share Posted October 30, 2007 Here is what I have so far, but I am getting an error. <?php $opt1 = $row3['option1']; $arrOptions = explode(', ', $opt1); echo "<select name='colors'>"; for ($i = 0, $intCnt = count($arrOptions); $i < $intCnt) { $strOption = trim($arrOptions[$i]); echo "<option value=\"$strOption\">$strOption</option>"; } // end for echo "</select>"; ?> The page is giving me the error: Parse error: parse error, unexpected ')', expecting ';' and it is on the line that starts the 'for' stmnt. What is not right there? Quote Link to comment https://forums.phpfreaks.com/topic/75298-solved-select-box-from-array/#findComment-381163 Share on other sites More sharing options...
eagleweb Posted October 30, 2007 Author Share Posted October 30, 2007 I hope this helps someone. It was simpler than I thought. I was making it too hard: $opt1 = $row3['option1']; $arrOptions = explode(', ', $opt1); $intCnt = count($arrOptions); echo "<select name='colors'>"; for ($i = 0; $i < $intCnt; $i++) { $strOption = trim($arrOptions[$i]); echo "<option value=\"$strOption\">$strOption</option>"; } // end for Quote Link to comment https://forums.phpfreaks.com/topic/75298-solved-select-box-from-array/#findComment-381242 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.