Jump to content

Populate a drop down with mysql data?


sean04

Recommended Posts

Hey!

 

So I have the following:

 

<?PHP
$Get_Sex = mysql_query("SELECT ID, Desc FROM gender") or die(mysql_error());
$Sex_Results = mysql_fetch_array($Get_Sex);

while($val = mysql_fetch_array($Sex_Results)){
echo "<option value=$val[iD]>$val[Desc]</option>";
}
?>

 

 

How come the drop down doesn't have any data in it?

 

Thanks,

Sean

Link to comment
https://forums.phpfreaks.com/topic/196200-populate-a-drop-down-with-mysql-data/
Share on other sites

Thanks for the replies! Still no luck..

 

This is what its looking like:


<form action="<?php echo $_SERVER["PHP_SELF"]; ?>" method="post">
                            
                                Email:
                                <input type="text" name="email" size="30" maxlength="25">
                                Password:
                                <input type="password" name="password" size="30" maxlength="25">
                                Confirm Password:
                                <input type="password" name="cpassword" size="30" maxlength="25">
                                Screen Name:
                                <input type="text" name="screenname" size="30" maxlength="55">
							Gender:
							<select name="gender" value="">Gender</option>
							<?PHP
							$Get_Sex = mysql_query("SELECT ID, Description FROM gender") or die(mysql_error());
							$Sex_Results = mysql_fetch_array($Get_Sex);
							while($val = mysql_fetch_array($Sex_Results)){
							echo "<option value=\"{$val['ID']}\">{$val['Description']}</option>";
							}
							?>
							</select>



                                <input type="submit" value="Register">
                        </form>

 

I know its not to neat right now sorry :P

 

Your using the wrong param for your fetch array in the while loop...

<?php
$Get_Sex = mysql_query("SELECT ID, Description FROM gender") or die(mysql_error());
while($val = mysql_fetch_array($Get_Sex)){
echo "<option value=\"{$val['ID']}\">{$val['Description']}</option>";
}
?>

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.