V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
luckylion
V2EX  ›  问与答

thinkphp 中 where 查询问题

  •  
  •   luckylion · 2015-12-19 00:29:20 +08:00 · 1444 次点击
    这是一个创建于 3056 天前的主题,其中的信息可能已经有所发展或是发生改变。

    table1
    id ----- uid ----- name ----- name2
    1 ----- 5 ----- wang ----- wanghu
    2 ----- 10 ----- li ----- litao

    $db=M('table1');
    $map['id']=1;
    $where['name']=array('like','%wa%');
    $where['name2']=array('like','%wa%');
    $where['_logic'] = 'or';
    $map['_complex'] = $where;

    //不解的地方
    $a=$db->where($map);
    $b=$db->where($map);

    echo $a->sum('uid');
    echo $b->sum('uid');

    //最终输出 5 和 15
    //如果将最后 4 句调成
    $a=$db->where($map);
    echo $a->sum('uid');

    $b=$db->where($map);
    echo $b->sum('uid');
    //这样就正确输出了全是 5

    /*
    但现在程序遇到需要在前面进行 where 拼接判断,最后才进行数据的查询,
    我以前用的程序可通过 copy()把 where 拷贝一份出来,不知 thinkphp 有没有这个功能,比如别的程序将最后 4 句改成
    */
    $a=$db->where($map);
    $b=$a->copy();

    echo $a->sum('uid');
    echo $b->sum('uid');

    目前尚无回复
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1429 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 16:56 · PVG 00:56 · LAX 09:56 · JFK 12:56
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.