简体   繁体   中英

php select id where id equals to 1 and 2

How to select id's that equals to two values, like id='1,2'

here is what I have:

mysql_query("SELECT * FROM menus WHERE active='1' AND lock=('1' ,'3') ") or die (mysql_error());

i'm new to mysql

Try this:

mysql_query("SELECT * FROM menus WHERE active='1' AND lock IN (1 ,3) ") or die   (mysql_error());

or this:

mysql_query("SELECT * FROM menus WHERE active='1' AND (lock = 1 OR lock = 3 ") or die   (mysql_error());

You would use the IN keyword.

So the SQL statement would be:

SELECT * FROM menus WHERE active='1' AND lock IN ('1', '3')

Don't forget to index things kids!

http://www.w3schools.com/sql/sql_in.asp

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM