search

Home  >  Q&A  >  body text

How does Thinkphp query the database in batches?

1. I have such a requirement: there are 4 kinds of inventory in the warehouse receipt. I want to check whether there is such inventory in the existing table. If there is, increase the quantity. If not, create new data; the where condition is an array. I should How to inquire?

2.where condition

Array
(
    [0] => Array
        (
            [warehouse] => 办公用品仓库
            [name] => 笔记本电脑
        )

    [1] => Array
        (
            [warehouse] => 办公用品仓库
            [name] => 笔记本电脑
        )

    [2] => Array
        (
            [warehouse] => 办公用品仓库
            [name] => 万用表
        )

    [3] => Array
        (
            [warehouse] => 办公用品仓库
            [name] => 鼠标
        )

)

3. Query statement, the following query is empty

$ch = $stock->where($where)->select();

I just learned it not long ago, and all the masters have provided me with some good ideas~~Thank you all

天蓬老师天蓬老师2837 days ago734

reply all(4)I'll reply

  • 大家讲道理

    大家讲道理2017-05-27 17:44:03

    where conditions:

        $where['warehouse'] = '办公用品仓库';
        $where['name'] = array('in', array('笔记本电脑','万用表','鼠标'));

    reply
    0
  • 仅有的幸福

    仅有的幸福2017-05-27 17:44:03

    // 去除 name 值,去重处理
    $where['name'] = ['in', implode(',', array_unique(array_column( $data, 'name')))];
    

    reply
    0
  • 高洛峰

    高洛峰2017-05-27 17:44:03

    thinkphp 3.23?

    $where['warehouse'] = '办公用品仓库';
    $where['name'] = array('in', array('笔记本电脑','万用表','鼠标'));
    //or
    $where['warehouse'] = '办公用品仓库';
    $where['name'] = array('in', '笔记本电脑,万用表,鼠标');

    thinkphp 5.0?

    where('warehouse','in','笔记本电脑,万用表,鼠标');
    // or
    where('warehouse','in',['笔记本电脑','万用表','鼠标']);

    reply
    0
  • 大家讲道理

    大家讲道理2017-05-27 17:44:03

    Correct answer upstairs. . . . . .

    reply
    0
  • Cancelreply