简体   繁体   中英

fetch data from mysql table using php ignoring some values?

I have a table which have a column with name domain_name . in domain_name column, different values stores like google.com , facebook.com , twitter.com etc. I try this which is working.

$query= 'Select * from accountdb WHERE domain_name="twitter.com" order by domain_name ASC';

But I want to pick that rows which have the values facebook.com , twitter.com in one query. I try this to achieve but not working.

$query= 'Select * from accountdb WHERE domain_name="twitter.com" and domain_name="facebook.com" order by domain_name ASC';

Alterring quotes

$query= "Select * from accountdb WHERE domain_name='twitter.com' and name='facebook.com' order by domain_name ASC";

Any hint would be appreciated.

And means that both conditions have to be met which will never ever happen. You want domain_name to be either "twitter.com" or "facebook.com". So you have to use or

$query= 'Select * from accountdb WHERE domain_name="twitter.com" or domain_name="facebook.com" order by domain_name ASC';

If you have more than 2 domains to check, best way is to use in.

$query= 'Select * from accountdb WHERE domain_name in ("twitter.com","facebook.com","google.com") order by domain_name ASC';

您可以使用OR

$query= 'Select * from accountdb WHERE domain_name="twitter.com" OR domain_name="facebook.com" order by domain_name ASC';

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