Jump to content


Photo

problem with list


  • Please log in to reply
4 replies to this topic

#1 Gruzin

Gruzin
  • Members
  • PipPipPip
  • Advanced Member
  • 448 posts
  • LocationGeorgia

Posted 07 September 2006 - 11:16 AM

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.

<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>

I don't need your script, I'll try to write it myself

#2 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 07 September 2006 - 11:22 AM

Your code isnt' quite there. Try this:
<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>

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.

#3 Gruzin

Gruzin
  • Members
  • PipPipPip
  • Advanced Member
  • 448 posts
  • LocationGeorgia

Posted 07 September 2006 - 11:25 AM

You are a PHP king, thank you very much :)
I don't need your script, I'll try to write it myself

#4 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 07 September 2006 - 11:26 AM

Try this...

<?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>

Regards
Rich

Edit: Damn it, why are my chubby digits sooooo slow at typing
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools

#5 Gruzin

Gruzin
  • Members
  • PipPipPip
  • Advanced Member
  • 448 posts
  • LocationGeorgia

Posted 07 September 2006 - 11:28 AM

Thank you HuggieBear, I've done and it works ;)
I don't need your script, I'll try to write it myself




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users