big-dog1965 Posted January 12, 2009 Share Posted January 12, 2009 How would I populate a drop down box with data from a mysql DB. I have a form it has a drop down box I want the data in that to be from the DB which will be a number from 1 to ...... when a selection from the drop down box is made it then populates the Cla_F_Name field in the form with the corasponing data to the number from the Cla_Cl_PK I tried this but does nothing no errors or anything. i dont really care about the echo "<b>No Records Found</b><br>"; }else{ echo "<b>Records Found</b><br>"; part more than likely it will always have data mysql_connect(localhost,$username,$password); @mysql_select_db($database) or die( "Unable to select database"); mysql_query($query); $query= 'SELECT Cla_Cl_PK, Cla_F_Name FROM Class_Alias_Cla ORDER BY Cla_Cl_PK DESC LIMIT 0, 100'; $result=mysql_query($query); $num=mysql_numrows($result); if ($num==0) { echo "<b>No Records Found</b><br>"; }else{ echo "<b>Records Found</b><br>"; } mysql_close(); $i=0; while ($i < $num) { $Cla_Cl_PK=mysql_result($result,$i,"Cl_F_Name"); $Cla_F_Name=mysql_result($result,$i,"ClaClPK"); echo "<b>$Cl_F_Name<br>$ClaClPK<hr>"; $i++; } ?> <h1>Class Alias</h1> <form enctype='multipart/form-data' action='Class_Alias_process.php' method='post'> <table width='75%' border=1 cellspacing="0" bordercolor="#0000FF"> <tr><td> Cla Act </td> <td width="184"> <input type=checkbox name='ClaAct' value="1" checked></td><td width="117"> Cla Cl PK</td> <td width="152"> <select size="1" name="Cla_Cl_PK"> </select></td></tr> <tr><td> Cla F Name</td> <td width="184"> <input type=text name='ClaFName' size="25"></td><td width="117"> </td> <td width="152"> <input type=text name='ClaClPK0'></td></tr> </table> <input type='submit' value='Submit Form'> <input type=reset value='Clear Form'></form> Link to comment https://forums.phpfreaks.com/topic/140450-inserting-data-into-a-drop-down-box-from-mysql/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.