问答详情
源自:2-6 条件构造器

order by

$res=$result->where('id','EXP','NOT in(20) ORDER BY id DESC')->select(); 这种类型怎么拼接order by,那位同学写过。这么写是错误的。直接order()方法没啥问题。

提问者:storyAs 2017-07-16 00:39

个回答

  • 我只是艾特
    2017-08-26 16:30:24
    已采纳

    建议你可以这样写:

    $where= array();

    $where['id'] = array('NOT IN','20');

    $res=$result->where($where)->order('id DESC')->select();

  • _神隐
    2019-07-28 15:05:58

    $sql = $db->whereOr([

              'id' => ['NOT IN',25],

           ])->order([

              'id' => 'desc'

           ])->select();

           

           dump($sql);


  • storyAs
    2017-07-16 00:45:22

    $res=$result->where([
       'id'=>['not in','22'],
    ])->order([
       'id'=>'asc'
    ])->select();


    output->

    D:\thinkphp\thinkphp\library\think\Debug.php:165:array (size=2)
     0 =>
       array (size=5)
         'id' => int 21
         'username' => string '这个杀手不太冷' (length=21)
         'password' => string '6e453d094299ca1c9935281e6b250d31' (length=32)
         'email' => string 'shashou@hotmail.com' (length=19)
         'num' => int 0
     1 =>
       array (size=5)
         'id' => int 20
         'username' => string '猩球大战' (length=12)
         'password' => string '914f21eb84c6fdb2b663dd6f453f65ca' (length=32)
         'email' => string 'imooc@163.com' (length=13)
         'num' => int 1