左关联查询,和,时间段查询(between),和, 方便调试的书写格式

本文介绍了一种使用PHP进行SQL查询的方法,包括左关联查询及基于时间段的查询。通过具体代码展示了如何实现这些查询,并返回相应的结果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

左关联查询:
function gdsearch()
{
    $con = $_POST['content'];
    if (!empty($con)) {
        $sql = "select waiqin.*,users.header from waiqin left join users on waiqin.uid=users.uid where waiqin.person='".$con."' or waiqin.cause='".$con."' or waiqin.time like '%$con%' ";
        $res = M()->query($sql);
        if ($res) {
            $code = array('code' => 1, 'message' => '请求成功');
            $result['list'] = $res;
            echo json_encode(array_merge($code,$result));
        } else {
            $code = array('code' => 2, 'message' => '没有数据');
            echo json_encode($code);
        }
    }
}
时间段查询(between):
if (!empty($data['uid']) && !empty($time1) && !empty($time2)){
    $sql = "select * from waiqin where time between ('".$time1."') and ('".$time2."') and uid in (".$data['uid'].")";
    $res = M()->query($sql);
    if($res!=null && $res!=false){
        $dc['content'] = $res;
        $excel = M('dcexcel')->add($data);
        if($excel){
            $code = array('code'=>1,'message'=>'添加导出记录成功');
            echo json_encode($code,$dc);
        }else{
            $code = array('code'=>2,'message'=>'添加记录失败');
            echo json_encode($code);
        }
    }else{
        $code = array('code'=>2,'message'=>'导出记录失败');
        echo json_encode($code);
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值