使用php在mysql中使用不同时间值的相同结果

时间:2017-01-28 12:07:19

标签: php mysql

    /*
    * Returns rows from the database based on the conditions
    * @param string name of the table
    * @param array select, where, order_by, limit and return_type conditions
    */

    public function getRows($table,$conditions = array()){
    $sql = 'SELECT ';
    $sql .= array_key_exists("select",$conditions)?$conditions['select']:'*';
    $sql .= ' FROM '.$table;
    if(array_key_exists("where",$conditions)){
        $sql .= ' WHERE ';
        $i = 0;
        foreach($conditions['where'] as $key => $value){
            $pre = ($i > 0)?' AND ':'';
            $sql .= $pre.$key." = '".$value."'";
            $i++;
        }
    }

    if(array_key_exists("order_by",$conditions)){
        $sql .= ' ORDER BY '.$conditions['order_by']; 
    }

    if(array_key_exists("start",$conditions) && array_key_exists("limit",$conditions)){
        $sql .= ' LIMIT '.$conditions['start'].','.$conditions['limit']; 
    }elseif(!array_key_exists("start",$conditions) && array_key_exists("limit",$conditions)){
        $sql .= ' LIMIT '.$conditions['limit']; 
    }


    $query = $this->db->prepare($sql);
    $query->execute();

    if(array_key_exists("return_type",$conditions) && $conditions['return_type'] != 'all'){
        switch($conditions['return_type']){
            case 'count':
                $data = $query->rowCount();
                break;
            case 'single':
                $data = $query->fetch(PDO::FETCH_ASSOC);
                break;
            default:
                $data = '';
        }
    }else{
        if($query->rowCount() > 0){
            $data = $query->fetchAll();
        }
    }
    return !empty($data)?$data:false;
}

以下是我获取结果的“我的代码”

$con_date ='2017/01/28';
            $convenue='plaza';
            $constime='12:00';
            $conetime='13:00';


    $checkvenue=$crud->getRows('temp_requests',array('where'=>array('t_date'=>$con_date,'t_venue'=>$convenue,'t_stime<= '.$constime.',t_etime> '.$constime.' OR t_stime<'.$conetime.', t_etime>='.$conetime.'')));

基本上我想确保任何现有记录都不会退出或不存在。 我在甚至改变上面的时间值上得到相同的结果......欢迎任何好事。谢谢

Reference For Condition i want

0 个答案:

没有答案