search

Home  >  Q&A  >  body text

Want to show checkbox for each row

Currently, in our office website, there is a user input text box. After insertion, the results of the database will be displayed below. There are 4 results for Lot ID, Product, EWSFLOW and Zone. Among them, only zone is different. I want to make it so that Lot ID, Product and EWSFlow must be displayed immediately, if the value entered has 5 different zones, the zone must be displayedZone: 1,2,3,4,5 . << The first problem has been solved. Now I try to add checkboxes for each area and the checkbox must appear next to each area. But currently, the checkbox is showing at the top. Additionally, the number of checkboxes must be the same as the number of regions. Assuming that the inserted value has 5 fields, in addition to this 5 checkboxes must be displayed (example: field: [checkbox] 1). Checkbox shown 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>";

P粉574695215P粉574695215265 days ago377

reply all(2)I'll reply

  • P粉450079266

    P粉4500792662024-04-02 09:04:12

    You can change the query and use MySQL's GROUP BY feature. Below is the query. Ignore any spelling errors.

    $sql = "SELECT lotid, product, ewsflow, GROUP_CONCAT(zone) FROM productdb.tbl_correlationwafer WHERE lotid = ? GROUP BY lotid, product, ewsflow ORDER BY lotid";
    
    $pq = $mysqli->prepare($sql);
    $pq->bind_param('i', $productlotid);
    $pq->execute();
    $result = $pq->get_result();
    
    $data = $result->fetch_all();

    GROUP_CONCAT() The function returns a string containing the concatenated non-NULL values ​​from the group.

    GROUP BY statement groups rows with the same value into summary rows, such as "Find the number of customers per country."

    reply
    0
  • P粉693126115

    P粉6931261152024-04-02 00:46:20

    You can define an array and put lotid, product and ewsflow into it and combine them inside a loop. Then check if it has been used before before echoing:

    $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 "";
    
    }

    reply
    0
  • Cancelreply