Gruzin Posted September 7, 2006 Share Posted September 7, 2006 hi guys,I am trying to get the data from db and display it as list. here is my code, but it displays the result on one line... Thanks in advance.[code]<select name="wordlist"> <option value="1" selected>Select Word</option> <option value="<?php require("config.php"); $result = mysql_query("SELECT * FROM spell"); while($row = mysql_fetch_array($result)) { echo $row['words']; } ?>"><?php $result = mysql_query("SELECT * FROM spell"); while($row = mysql_fetch_array($result)) { echo $row['words']; } ?></option></select>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/19999-problem-with-list/ Share on other sites More sharing options...
wildteen88 Posted September 7, 2006 Share Posted September 7, 2006 Your code isnt' quite there. Try this:[code=php:0]<select name="wordlist"> <option value="1" selected>Select Word</option><?phprequire("config.php");$result = mysql_query("SELECT * FROM spell");while($row = mysql_fetch_array($result)){ // echo the html: // option value="word">word</option> echo '<option value="' . $row['words'] . '"> ' . $row['words'] . "</option>\n ";}?></select>[/code]Notice I have echo'd the html in the while loop. And not just the $row['words'] variable. If you are creating a drop down list you'll need to echo the html option tag along with the variable, in order create a new option in the drop down list. Quote Link to comment https://forums.phpfreaks.com/topic/19999-problem-with-list/#findComment-87646 Share on other sites More sharing options...
Gruzin Posted September 7, 2006 Author Share Posted September 7, 2006 You are a PHP king, thank you very much :) Quote Link to comment https://forums.phpfreaks.com/topic/19999-problem-with-list/#findComment-87649 Share on other sites More sharing options...
HuggieBear Posted September 7, 2006 Share Posted September 7, 2006 Try this...[code]<?phpphp require("config.php");$result = mysql_query("SELECT * FROM spell");?><select name="wordlist"> <option value="1" selected>Select Word</option><?php while($row = mysql_fetch_array($result)){ echo "<option value=\"$row['words']\">$row['words']</option>\n"; }?></select>[/code]RegardsRich[color=red]Edit: Damn it, why are my chubby digits sooooo slow at typing[/color] Quote Link to comment https://forums.phpfreaks.com/topic/19999-problem-with-list/#findComment-87651 Share on other sites More sharing options...
Gruzin Posted September 7, 2006 Author Share Posted September 7, 2006 Thank you HuggieBear, I've done and it works ;) Quote Link to comment https://forums.phpfreaks.com/topic/19999-problem-with-list/#findComment-87653 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.