nezbo Posted June 22, 2007 Share Posted June 22, 2007 Hi all, i am very new to php, and i am trying to get a dropdown box that will populate from a MySql Database, I have a sites database, and want to select it from a dropdown box... Hope this make sense. ??? Neil Link to comment https://forums.phpfreaks.com/topic/56700-newbe-help-with-dropdown-box-from-mysql-database/ Share on other sites More sharing options...
supanoob Posted June 22, 2007 Share Posted June 22, 2007 what do you mean you want information from a database to be shown in a dropdown box? if so use a while loop and loop the <option>$data</option> part of the dropdown field. Link to comment https://forums.phpfreaks.com/topic/56700-newbe-help-with-dropdown-box-from-mysql-database/#findComment-280031 Share on other sites More sharing options...
nezbo Posted June 22, 2007 Author Share Posted June 22, 2007 That is excactly what i mean, cheers supanoob I will try it... Link to comment https://forums.phpfreaks.com/topic/56700-newbe-help-with-dropdown-box-from-mysql-database/#findComment-280097 Share on other sites More sharing options...
nezbo Posted June 22, 2007 Author Share Posted June 22, 2007 I have tryed it and i cant get it to work :'( this is my code what is going wrong? $getSiteName = mysql_query("SELECT SiteName FROM site"); if (!$getSiteName) { echo 'Could not run query: ' . mysql_error(); exit; } echo "<table align=center border=0><tr>"; echo "<tr><td colspan=2 align=center><h2>Log a Job</h2><tr><td>"; echo "<form action=doLogJob.php method=post>"; echo "<tr><td align=left>Current User : <td align=left>" . $_COOKIE["user"] . "</td></tr>"; echo "<tr><td align=left>PCIU Number : <td align=left><input type=text NAME=pciuno></td></tr>"; echo "<tr><td align=left>Site Name : <td align=left><select NAME=SiteName1></td></tr>"; while($row = mysql_fetch_array()) { echo "<option value='please select a site', $row>$row</option>"; } echo "<tr><td align=left>Reported By : <td align=left><input type=text NAME=RepBy></td></tr>"; echo "<tr><td align=left VALIGN=top>Problem :<td align=left> <TEXTAREA NAME=Problem ROWS=17 COLS=70></TEXTAREA></td></tr>"; echo "<tr><td align=left>Date : <td align=left><input type=text NAME=callDate value='$callDate'></td></tr>"; echo "<tr><td align=left>Time : <td align=left><input type=text NAME=callTime value='$callTime'></td></tr>"; echo "<tr><td><input type=submit value=Submit><td><input type=reset name=Reset value=Reset></td></tr>"; echo "</form>"; echo "</tr></table>"; Link to comment https://forums.phpfreaks.com/topic/56700-newbe-help-with-dropdown-box-from-mysql-database/#findComment-280117 Share on other sites More sharing options...
supanoob Posted June 23, 2007 Share Posted June 23, 2007 you dont seem to of defined $row. it seems to be missing something like $row=($row['sitename']); try this: <?php $query="select <your data> from <your table> where <your criteria>"; $result=mysql_query($query); if (!$result) { die(mysql_error()); } $num_rows=mysql_num_rows($result); echo "<table align=center border=0><tr>"; echo "<tr><td colspan=2 align=center><h2>Log a Job</h2><tr><td>"; echo "<form action=doLogJob.php method=post>"; echo "<tr><td align=left>Current User : <td align=left>" . $_COOKIE["user"] . "</td></tr>"; echo "<tr><td align=left>PCIU Number : <td align=left><input type=text NAME=pciuno></td></tr>"; echo "<tr><td align=left>Site Name : <td align=left><select NAME=SiteName1>"; while ($row=mysql_fetch_array($result)){ $row=($row['<your row name>']); echo "<option value='please select a site', $row>$row</option>"; } echo "<tr><td align=left>Reported By : <td align=left><input type=text NAME=RepBy></td></tr>"; echo "<tr><td align=left VALIGN=top>Problem :<td align=left> <TEXTAREA NAME=Problem ROWS=17 COLS=70></TEXTAREA></td></tr>"; echo "<tr><td align=left>Date : <td align=left><input type=text NAME=callDate value='$callDate'></td></tr>"; echo "<tr><td align=left>Time : <td align=left><input type=text NAME=callTime value='$callTime'></td></tr>"; echo "<tr><td><input type=submit value=Submit><td><input type=reset name=Reset value=Reset></td></tr>"; echo "</form>"; echo "</tr></table>"; ?> Things to change: <your data> = this should be everything you want pulling from your table <your table> = the table you want your data to be pulled from <your criteria> = What you want the data to be eg "where account_id='1'" <your row name> = in your case i think it is SiteName not sure. but i think this might work, it is how i would of done it anyway. Also note how i removed the </td></tr> from the end of <select NAME=SiteName1> that caused a problem too. Hope this helps anyway. Link to comment https://forums.phpfreaks.com/topic/56700-newbe-help-with-dropdown-box-from-mysql-database/#findComment-280767 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.