Skip to content
Advertisement

stop updating column value when status is settled for similar lead id using PHP, MYSQL [closed]

i have a following mysql table, where multiple user has accepted a lead (lead_id). here i want to stop updating table column ‘Value’ when ‘status’ is ‘settled

<?php
    
$sql = "SELECT `status`,`email_id` FROM `deal_request` WHERE `client_id` = '$client_id'";
$query = mysqli_query($connection, $sql);
if ($query->num_rows > 0) {
    while ($row = mysqli_fetch_assoc($query)) {
        $status = $row['status'];
             
        if ($status == 'pending') {
            $sql = "UPDATE `deal_request` SET `status`='settled',`share_userdetails` ='2' WHERE `client_id`='$client_id' AND `dealer_id`='$dealer_id'";
            $query = mysqli_query($connection, $sql);
            if ($query == true) {
                echo " <script>
                                alert("You Have Successfully Released The Lead");
                                window.location.replace("LeadDetails.php?client_id=$client_id&&dealer_id=$dealer_id");
                                </script>";
            }
        } else {
            echo 'you can not change';
            echo " <script>
                            alert("You cannot select this dealer, another dealer has been selected aleady!");
                            window.location.replace("LeadDetails.php?client_id=$client_id&&dealer_id=$dealer_id");
                        </script>";
        }
    }
}
?>

enter image description here

Advertisement

Answer

Get the count of rows with status = 'settled'. If it’s more than 0, don’t allow accepting the lead.

$stmt = $connection->prepare("
    SELECT COUNT(*) AS count 
    FROM deal_request 
    WHERE client_id = ? AND status = 'settled'");
$stmt->bind_param("i", $client_id);
$stmt->execute();
$result = $stmt->get_result();
$row = $result->fetch_assoc();
if ($row['count'] == 0) {
    // code to accept the lead
} else {
    // code to report that the lead cannot be accepted
}
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement