Reputation: 23
I'm displaying data from MySQL DB in a tabular form in HTML and PHP. Here, each 'order' has its own 'status' i.e., every row should have 2 radio buttons to change its status. Though it displays all the radio buttons, the problem is I'm unable to select a radio button FOR EACH ROW, I can only select single radio button FOR ALL THE ROWS!
<?php
$con3 = mysqli_connect($mysql_hostname, $mysql_usrnm,$mysql_pass, "customer") or die("Ouch!");
$sql_query = " SELECT * FROM order_info WHERE deptt='".$_SESSION['deptt']."'";
$result = mysqli_query($con3, $sql_query);
if (!$result) {
printf("Error: %s\n", mysqli_error($con3));
exit(); }
echo '<table border="0px">';
echo'<th>Product</th><th>Type</th><th>Quantity</th><th>Order Status</th>';
while ($row = mysqli_fetch_array($result)){ //Tabular Data
$type=$row["type"];
$make=$row["make"];
$quantity=$row["quantity"];
echo "<tr>";
echo "<td>" . $row['type'] . "</td>";
echo "<td>" . $row['make'] . "</td>";
echo "<td>" . $row['quantity'] . "</td>";
echo '<td><cb><input type="radio" name="status" value="not approved">Not Approved<br>
<input type="radio" name="status" value="approved">Approved</cb></td>';
}
echo "</table>";
?>
How do I fix this?
Upvotes: 0
Views: 5176
Reputation: 18123
You should change the name
of the input. I am guessing that you also have a database field called id
, so I'll use that in the example:
echo '<td><cb><input type="radio" name="status[' . $row['order_id'] . ']" value="not approved">Not Approved<br>
<input type="radio" name="status[' . $row['order_id'] . ']" value="approved">Approved</cb></td>';
Also when you process your form, you can get the value by using for example $_POST['status'][2]
for the row with id=2. You can easily loop the $_POST['status']
.
Upvotes: 4
Reputation: 3609
Add a number, I recommend the internal id of the "order", to the end of the "name" value, like
name="status123"
Upvotes: 0