Question

I'm trying to minus the variable from the database I stored. Being trying my luck but unable to solve it. So I doing a recruiting process for example I opened 2 vacancy for this job position title and job type then when someone apply and I hired him/her the vacancy must minus one in the database. Thanks in advance! So this is my code:

<?php
    if ($applied_position_title == $position_title && $applied_job_type == $job_type) {
        echo $vacancy;
        $output = --$vacancy;
        echo $output;
    }
    $query_status = "UPDATE job_opening SET closing_date = DATE('$newdate'), creator_id = '$creator_id', job_opening_status = 'Closed', vacancy = '$output' WHERE '$job_accepted' = 'Yes' AND '$applied_position_title' = position_title AND '$applied_job_type' = job_type";
    $result_status = mysqli_query($link, $query_status) or die(mysqli_error($link));
    echo $query_status;
?>
Was it helpful?

Solution

Try vacancy = (vacancy-1) in query

$query_status = "UPDATE job_opening SET closing_date = DATE('$newdate'), creator_id = '$creator_id', job_opening_status = 'Closed', vacancy = (vacancy-1) WHERE '$job_accepted' = 'Yes' AND '$applied_position_title' = position_title AND '$applied_job_type' = job_type";

OTHER TIPS

Do an update query like this:

UPDATE `your_table` SET `filed_name` = (`filed_name` - 1) WHERE `some_id` = 1
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top