dropdown menu using database table?
Posted: Tue Sep 11, 2007 9:15 pm
Hi again,
I'm trying to figure out how to make a dropdown menu using values from a table (actually probably from 2 columns. Ok, here's a rundown:
I've got a table called prices; it has 2 columns: size, price. Sizes are 5x7, 8x10, 11x14, etc. The corresponding prices are 20.00, 25.00, 45.00, etc. So I want the dropdown menu to pull all the values from the corresponding columns. For example, 5x7 for $20.00, 8x10 for $25.00, etc. I am then working on taking the print size and corresponding price chosen and making a simple shopping cart to submit orders of several prints ordered.
This is what I have now which works fine if I don't have to use the information later that the customer chose:
I have found some examples but they don't incorportate into html tables like I have (I know, a pain). One such example that seems promising is this:
I have no idea what else to do. This is a whole new territory for me, and my MySql/PHP skills are quite limited. Using a great book to walk me through this, but it doesn't do advanced stuff like this. Any help would be greatly appreciated
Thanks so much!
I'm trying to figure out how to make a dropdown menu using values from a table (actually probably from 2 columns. Ok, here's a rundown:
I've got a table called prices; it has 2 columns: size, price. Sizes are 5x7, 8x10, 11x14, etc. The corresponding prices are 20.00, 25.00, 45.00, etc. So I want the dropdown menu to pull all the values from the corresponding columns. For example, 5x7 for $20.00, 8x10 for $25.00, etc. I am then working on taking the print size and corresponding price chosen and making a simple shopping cart to submit orders of several prints ordered.
This is what I have now which works fine if I don't have to use the information later that the customer chose:
Code: Select all
echo '<tr>';
echo '<td><font size="1" face="Arial, Helvetica, sans-serif">';
echo '<select name="quantity" class="menubox" id="quantity" style="width:140;">';
echo '<option selected>Select Print Size</option>';
echo '<option>8 wallets: $' . $row['8wallets'] . '</option>';
echo '<option>5x7: $' . $row['5x7'] . '</option>';
echo '<option>8x10: $' . $row['8x10'] . '</option>';
echo '<option>11x14: $' . $row['11x14'] . '</option>';
echo '<option>16x20: $' . $row['16x20'] . '</option>';
echo '<option>20x24: $' . $row['20x24'] . '</option>';
echo '<option>20x30: $' . $row['20x30'] . '</option>';
echo '</select>';
echo '</font></td>';
echo'</tr>';Code: Select all
echo "<select name='state'>";
while($row = mysql_fetch_assoc($result)) {
echo "<option value='$row[state_name]'";
if (previously selected option == $row['state_name']) {
echo " selected='selected'";
}
echo ">$row[state_name]";
}
echo "</select>";