Currently, in our office website, there is a userinput textbox and after inserting, results from database will be shown below. There are 4 results Lot ID, Product, EWSFLOW and Zone
.Among them, only zone is different. I want to do that Lot ID, Product and EWSFlow
must show at once and if that entered values have 5 different zones, Zone must shown Zone: 1,2,3,4,5
. << First problem has been solved. And right now, I tried to add check boxes for each zone and checkbox must shown beside each zone. But currently, checkboxes are showing at the top. Also, count of the checkboxes must be same as Zones. lets say if the inserted value have 5 zones, it has to show 5 checkboxes besides of it (Example: Zone : [checkbox] 1).
Checkboxes are showing at top
echo "<table id='corwafer'>";
$arr = array();
while ($row = mysqli_fetch_assoc($result1)) {
$field1name = $row["lotid"];
$field2name = $row["product"];
$field3name = $row["ewsflow"];
$field4name = $row["zone"];
$key = $field1name + ":" + $field2name + ":" + $field3name;
if (!in_array($key, $arr)){
echo "<tr>";
echo "<th >Lot ID:</th>";
echo "<td >$field1name</td>";
echo "</tr>";
echo "<tr>";
echo "<th>Product:</th>";
echo "<td>$field2name</td>";
echo "</tr>";
echo "<tr>";
echo "<th>EWSFLOW: </th>";
echo "<td>$field3name</td>";
echo "</tr>";
array_push($arr, $key);
}
echo "<tr>";
echo "<th>Zone:</th>";
echo "<input type='checkbox' name='chkzone' value='chkzone'>";
echo "<td>$field4name</td>";
echo "</tr>";
}
echo "</table>";
My Answer:
To display the checkboxes beside each zone instead of at the top, you can modify your code as follows:
php
echo "";
$arr = array();
while ($row = mysqli_fetch_assoc($result1)) {
$field1name = $row["lotid"];
$field2name = $row["product"];
$field3name = $row["ewsflow"];
$field4name = $row["zone"];
$key = $field1name . ":" . $field2name . ":" . $field3name;
if (!in_array($key, $arr)){
echo "";
echo "Lot ID: ";
echo "$field1name ";
echo " ";
echo "";
echo "Product: ";
echo "$field2name ";
echo " ";
echo "";
echo "EWSFLOW: ";
echo "$field3name ";
echo " ";
array_push($arr, $key);
}
echo "";
echo "Zone: ";
echo "$field4name ";
echo " ";
}
echo "
";
In this code snippet, I have added `[]` to the `name` attribute of the checkbox to make it an array. This way, you will receive an array of selected zones when the form is submitted. Additionally, I have corrected the concatenation operator from `+` to `.` in the `$key` variable assignment.
Rate this post
3 of 5 based on 4059 votesComments