如果请输入订单编号或订单ID的时候,当输入订单编号就会找到订单编号或者输入订单ID就会找到订单ID。
创建sql订单表如下:
--
-- Table structure for table `w_order`
--
CREATE TABLE `w_order` (
`id` int(11) NOT NULL,
`order_num` int(11) NOT NULL,
`name` varchar(200) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
--
-- Indexes for dumped tables
--
--
-- Indexes for table `w_order`
--
ALTER TABLE `w_order`
ADD PRIMARY KEY (`id`);
--
-- AUTO_INCREMENT for dumped tables
--
--
-- AUTO_INCREMENT for table `w_order`
--
ALTER TABLE `w_order`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;
插入语句:
INSERT INTO `w_order` (`id`, `order_num`, `name`) VALUES ('1', '11001', '饼干'), ('2', '1102', '咖啡');
像上面搜索框里面请输入订单编号或订单ID的图片,怎么查询ID或者订单编号呢?用sql语句是否能查询到吗?
使用 LIKE 子句
如果要求用户输入正确的订单编号才能查到的话,就用
WHERE order_num=xxxx
就行了。如果允许用户进行搜索,就用
WHERE order_num LIKE xxxx
。