Jump to content

problem with list


Gruzin

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]
Link to comment
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.
Link to comment
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]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.