我正在使用 Codeigniter 执行一些任务,但我在查询搜索中遇到了问题。我在 mysql 中有以下数据:
order_billing
--------------
19001-00001-32222
13501-00021-31122
13344-02351-16072
18701-00001-30922
11123-12301-12122
order_billing 有 3 部分格式:number_1-number_2-number_3
然后我像这样制作搜索表单
<input type="text" name="order_billing_1">-
<input type="text" name="order_billing_2">-
<input type="text" name="order_billing_3">
当for with condition时,我如何进行SQL查询
- 输入“order_billing_1”搜索“number_1”
- 输入“order_billing_2”搜索“number_2”
- 输入“order_billing_3”搜索“number_3”
我写了一些这样的代码
$post = $this->input->post();
$search['number_1'] = $post['order_billing_1'];
$search['number_2'] = "-".$post['order_billing_2'];
$search['number_3'] = "-".$post['order_billing_3'];
和这样的查询
$this->db->like('order_billing', '$search['number_1']', 'after');
$this->db->or_like('order_billing', '$search['number_2']', 'both');
$this->db->or_like('order_billing', '$search['number_3']', 'before');
但还是不对。我仍然对如何在手动 SQL 查询中进行搜索感到困惑。
$search['number_1'] = $post['order_billing_1'];
$search['number_2'] = "-".$post['order_billing_2'];
$search['number_3'] = "-".$post['order_billing_3'];
查询
Select * from TABLE WHERE order_billing like ????
有人知道怎么解决吗?
最佳答案
为什么不把它做成一长串呢?
$order_billing = $post['order_billing_1']."-".
$post['order_billing_2']."-".
$post['order_billing_3'];
然后您可以在简单的查询中使用它。
请注意,我使用 $post
而不是 $_POST
来模仿您所做的。
关于php - SQL如何在一个字段中搜索某个部分?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55630591/