Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading