herghost Posted March 24, 2010 Share Posted March 24, 2010 Hi all, I have the below: <?php $query0 = "SELECT * FROM product_package"; $result0 = mysql_query($query0); echo '<dl>'; echo '<dt>'; echo '<label for="package_id">Product Package:</label>'; echo '</dt>'; echo '<dd>'; echo '<select size="1"name="package_id" id="package_id">'; while ($list0 = mysql_fetch_assoc($result0)) { $p_id = $list0['package_id']; $p_name = $list0['package_name']; echo '<option value='; echo $p_id; echo '>'; echo $p_name; echo '</option>'; echo '</select>'; echo '</dd>'; echo '</dl>'; } ?> Which works fine if their is only one result in the database, however if there is more then they just get listed under dropdown box. I am guessing that I need a foreach statement, but not sure how I implement one. Link to comment https://forums.phpfreaks.com/topic/196329-select-box-from-database-foreach-help/ Share on other sites More sharing options...
herghost Posted March 24, 2010 Author Share Posted March 24, 2010 Got It! <?php $query0 = "SELECT * FROM product_package"; $result0 = mysql_query($query0); echo '<dl>'; echo '<dt>'; echo '<label for="package_id">Product Package:</label>'; echo '</dt>'; echo '<dd>'; echo "<select name=package_id value=''>Package Name</option>"; while ($list0 = mysql_fetch_array($result0)) { echo "<option value=$list0[package_id]>$list0[package_name]</option>"; } echo '</select>'; echo '</dd>'; echo '</dl>'; ?> Link to comment https://forums.phpfreaks.com/topic/196329-select-box-from-database-foreach-help/#findComment-1030930 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.