lundi 30 janvier 2023

If there is like 5 checkboxes, I can't uncheck the checkboxes randomly. I can only uncheck one by one

I uncheck the checkboxes, database value got update to 0 from 1. But I can't uncheck the checkboxes randomly. I can only uncheck one by one. Example, there is like 5 results, I can uncheck from 1 to 5 in order. I want to do is uncheck randomly like 5 2 3 1.

Result

  </div>
  <div id="result" style="display: inline-table; margin-left: 150px; margin-top: 22px;">
  <?php
                include("correlationwafer_result.php");
    ?></div>
  <!--div id="result" ></div-->
  <div class="col-sm-10">
   </div>`

Below is correlationwafer_result.php.

<?php 

// ini_set("memory_limit","512M");
include("_dbconn.php");
include("//sgewsnant21.amk.st.com/ewsweb/wwwroot/library/common7/db_config.inc");
include("//sgewsnant21.amk.st.com/ewsweb/wwwroot/library/common7/standard_defines.inc");
session_start();


$productlotid = isset ($_GET['productlotid'])? $_GET['productlotid']:'';
$zone_enable = isset ($_GET['zone_enable'])? $_GET['zone_enable']:'';
$zone_enablee = isset ($_GET['zone_enablee'])? $_GET['zone_enablee']:'';
//$sql1 = "Update * FROM productdb.tbl_correlationwafer WHERE lotid = '$productlotid' ORDER BY lotid and zone_enable='0'";
$sql = "SELECT * FROM productdb.tbl_correlationwafer WHERE lotid = '$productlotid' ORDER BY product asc, zone asc";
    $result1 = mysqli_query($conn,$sql);
    $row_cnt = mysqli_num_rows($result1);

echo '<table class="table table-bordered table-striped">';
echo "<thead>
    <tr>
    <th>Lot ID</th>
    <th>Product</th>
    <th>Zone</th>
    <th>Enable</th>
    </tr>
    </thead>";
    
    while($row = mysqli_fetch_array($result1))
    {
        echo '<tr>';
        echo '<td>'.$row['lotid'].'</td>';
        echo '<td>'.$row['product'].'</td>';
        echo '<td>'.$row['zone'].'</td>';
        echo "<td><input type='checkbox' name='zone_enable' id='zone_enablee' value='1' onchange='Submitt(\"".$row['zone']."\",\"".$row['lotid']."\")'";
        if($row['zone_enable']==1) {
            echo "checked='checked'"; 
        }
        echo "></td>";
        echo '</tr>';
    }
echo '</table>';

?>


<script type="text/javascript">

function Submitt(zone,productlotid){
    var xhr = new XMLHttpRequest();
    var checkbox = document.getElementById("zone_enablee");
    var value = checkbox.checked ? 1 : 0;
    xhr.open("GET", "test_1.php?zone="+zone+"&value="+value+"&productlotid="+productlotid, true);
    xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xhr.onreadystatechange = function() {
        if (xhr.readyState === 4 && xhr.status === 200) {
            console.log(xhr.responseText);
            if(!checkbox.checked){
                console.log("Record updated successfully");
            }
        }
    }
    xhr.send();
}


</script>

Below is from test_1.php.

<?php 

// ini_set("memory_limit","512M");
include("_dbconn.php");

$zone = $_GET['zone'];
$value = $_GET['value'];
$productlotid = $_GET['productlotid'];

    $sql = "UPDATE productdb.tbl_correlationwafer SET zone_enable = '$value' WHERE lotid = '$productlotid' AND zone = '$zone'";

        if (mysqli_query($conn, $sql)) {
            echo "Record updated successfully";
        } else {
            echo "Error updating record: " . mysqli_error($conn);
        }

echo json_encode($response);
mysqli_close($conn);
?>



Aucun commentaire:

Enregistrer un commentaire