Jump to content

[SOLVED] How do I get php to display results in a form drop down menu?


pneudralics

Recommended Posts

I got it to display but how do I make it so it's not all one line? The below will show all the results in one line.

 

    <select name="category">
  	<option>
<?php
$querycategory = 'SELECT * FROM category';
if ($cresult = mysql_query ($querycategory)) {

while ($crow = mysql_fetch_array ($cresult)) {
$category = $crow['category'];
echo "$category";
}
}
?>
    </option>
</select>

Your <option></option> tags need to be within your while loop,

 

while ($crow = mysql_fetch_array ($cresult)) {
   $category = $crow['category'];
   echo "<option>$category</option>";
   }

 

Only the <select></select> tags need to be outside of your loop

Your <option></option> tags need to be within your while loop,

 

while ($crow = mysql_fetch_array ($cresult)) {
   $category = $crow['category'];
   echo "<option>$category</option>";
   }

 

Only the <select></select> tags need to be outside of your loop

 

Thanks

Archived

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

×
×
  • 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.