bemax Posted December 28, 2010 Share Posted December 28, 2010 Hi, I'm trying to get data from one field in a table (database). But I get undesirable result: Here is my code -> <?php $result2 = mysql_query("SELECT DISTINCT theme FROM mytable ") or die(mysql_error()); while($row2 = mysql_fetch_array( $result2 )) { ?> <form method="post" action='<?php echo $_SERVER["PHP_SELF"]; ?>'> <select name='themes'"> <?php $arr= array($row2['theme']); foreach($row2 as $value) { echo "<option value='$value'><b>". $value."</b> </option><br> "; } } ?> The attached image file show the result that I don't wont. (It's not a dropdown). Is there anyone who may help me, I spent a lot of time to find out but I can't. Thanks a lot for your help [attachment deleted by admin] Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted December 28, 2010 Share Posted December 28, 2010 each time you loop and get the next record, you are creating a new form and a new select. the form and select should only be created once. therefore, i suggest that you move the <form> and <select> code to before the while loop. you'll also need to close the select and the form after the while loop. Quote Link to comment Share on other sites More sharing options...
Maq Posted December 28, 2010 Share Posted December 28, 2010 Blue is right, but it would be helpful if you provide what you want and what you're actually getting. Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted December 28, 2010 Share Posted December 28, 2010 hm, many other problems. i think you're trying to do this: <form method="post" action=''> <select name='themes'> <?php $result2 = mysql_query("SELECT DISTINCT theme FROM mytable ") or die(mysql_error()); while($row2 = mysql_fetch_array( $result2 )) { $value = $row2['theme']; echo "<option value='$value'>$value</option> "; } ?> </select> </form> Quote Link to comment 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.