Jump to content

Archived

This topic is now archived and is closed to further replies.

Gruzin

problem with list

Recommended Posts

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]

Share this post


Link to post
Share on other sites
Your code isnt' quite there. Try this:
[code=php:0]<select name="wordlist">
  <option value="1" selected>Select Word</option>
<?php
require("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.

Share this post


Link to post
Share on other sites
Try this...

[code]
<?php
php 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]

Regards
Rich

[color=red]Edit: Damn it, why are my chubby digits sooooo slow at typing[/color]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.