Jump to content

form variables from database help.


herghost

Recommended Posts

Hi all,

 

I would like to have a form that gives you options based on the results of an mysql query.

 

My example is this, say I have a mysql row with the colum name points and the result is 5. How would I populate a form with a drop down box with the options 1 or 5. Ie the user can select either a single point they have or all 5?

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/178307-form-variables-from-database-help/
Share on other sites

Hi Just use something like the demo from the Tizag site.

 

<?php
// Make a MySQL Connection
$query = "SELECT * FROM example"; 

$result = mysql_query($query) or die(mysql_error());


while($row = mysql_fetch_array($result)){
echo $row['name']. " - ". $row['age'];
echo "<br />";
}
?>

 

But now change the while.

 

 

<select name="DropDown">
<?php
// Make a MySQL Connection
$query = "SELECT * FROM example"; 

$result = mysql_query($query) or die(mysql_error());


while($row = mysql_fetch_array($result)){
echo "<option value='";
        echo $row['name'];
        echo "'>";
        echo $row['name'];
        echo "</option>";
}
?>
</select>

 

All the bits inside the while could be condensed into one line but I've put it on several here to make it more clear.

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.