On my website, I have a PHP query that returns various deli results from mysql database. For each result that is returned, I would like the same set of radio options to appear. The radio buttons will always be the same and represent how many pounds.
An example of what I currently have
Returned results:
-Roast Beef (CheckBox)
-Ham (CheckBox)
-Salami (CheckBox)
Here is what I would like to have
Returned results:
-Roast Beef (CheckBox)
-Ham (CheckBox)
-Salami (CheckBox)
I have one table called deli_items. Do I need another table that contains quantities? How would I change my PHP code?
SELECT
$sql_deli_meat="SELECT * FROM $tbl_name WHERE enabled = 1 AND ingredient_type = 'deli_meat' ORDER BY sort ASC";
$result_deli_meat=mysql_query($sql_deli_meat);
PHP
<?php while($rows=mysql_fetch_array($result_deli_meat)){ ?>
<input type="checkbox" name="meats[]" id="<? echo $rows['itemname']; ?>" value="<? echo $rows['label']; ?>" style="display:none;" onclick="ShowMe();" class="green-border-meats price-update" />
<a id="<? echo $rows['itemname']; ?>" class="radio-picture-meats" href="javascript:set_radio('<? echo $rows['itemname']; ?>');"><span class="item_label"><? echo $rows['displayname'];?></span><span class="item_label_price">Per Pound<BR>$<? echo $rows['price'];?></span><img class="box" src="<? echo $rows['imagepath']; ?>" width="300px" height="215px"/></a>
<?php } ?>
You're already inside of your PHP tags, so you do not need to re-enter PHP when echoing rows.
This is what your updated while loop should look like:
while($row = mysql_fetch_array($result_deli_meat)){
$itemName = $row['itemname'];
echo '<input type="checkbox" name="meats[]" id="'$itemName'" value="'$itemName'">';
}
Just as a little heads up, you should DEFINITELY update from the older, deprecated mysql_*
to something such as PDO or the newer MySQL improved extension. The old extension is extremely unsafe and prone to SQL injection.