Implement Hybrid FCFS + Priority Queue in SQL and PHP

23 views Asked by At

I would like to ask if how can the SQL rearrange the database simultaneously after there is an new input.

Sample data:

Sample Data

I want to follow the Hybrid FCFS + Priority where 1:1 ratio, 1 regular and 1 priority simultaneously.

The identifier of Priority here is when the Priority = 1 of that input.

Here the sample PHP script code but I am stucked here, I don't know if I will modify the code in PHP or it is directly statemented in SQL database

    function save_queueSAMPLE(){
        extract($_POST);

        if($priority == 1){
        }
        else{
            $sql = "INSERT INTO `queue_listSAMPLE` (`customer_name`,`priority`) VALUES('{$customer_name}','{$priority}')";
            $save = $this->query($sql);
    
            if($save) {
                $resp['status'] = 'success';
                $resp['id'] = $this->query("SELECT last_insert_rowid()")->fetchArray()[0];
            } else {
                $resp['status'] = 'failed';
                $resp['msg'] = "An error occured. Error: ".$this->lastErrorMsg();
            }
    
            return json_encode($resp);
        }
    }
0

There are 0 answers