如何使用mysql php在搜索中过滤设置

时间:2013-11-19 15:47:57

标签: php mysql

我有2个类别

1.worker
2.staff

我有1行cardno

w12        (this is worker id format)
s109   and (this is staff id format)

我想只显示以s字母

开头的员工ID

我该怎么做?

SELECT * 
FROM accounts 
where cardno 
AND date BETWEEN '$a' 
AND '$b' 
order by date ASC

3 个答案:

答案 0 :(得分:2)

您可以使用LIKE子句:

SELECT *
FROM accounts
WHERE date BETWEEN '$a' AND '$b'
  AND cardno LIKE 's%'
ORDER BY date ASC

答案 1 :(得分:1)

SELECT *
FROM accounts
WHERE cardno LIKE 's%'
  AND DATE BETWEEN '$a' AND '$b'
ORDER BY DATE ASC

LIKE运算符用于在列中搜索指定的模式。 's%'表示以s开头的任何单词值。

答案 2 :(得分:0)

您可以使用LEFT

SELECT *
FROM accounts
WHERE 
  DATE BETWEEN '$a' AND '$b'
AND LEFT(cardno ,1) ='s' /* or S */
ORDER BY DATE ASC
  

返回字符串str中最左边的len个字符,如果是,则返回NULL   任何参数都是NULL。

LEFT(str,len)