Wallchris
Wallchris

Reputation: 33

Selecting multiple rows using WHERE function

I am trying to search for multiple rows within a database using the PDO handler, using the WHERE function to search for multiple row/variables. I can successful search for individual items using just one name variable, however I was hoping to search for multiple. This is what I've tried but its not working:

$result=$dbh->prepare("SELECT * FROM hire WHERE name='item1', 'item2", 'item3');

Thank you very much for your help :)

Upvotes: 1

Views: 54

Answers (1)

andrzejwp
andrzejwp

Reputation: 952

If you want to choose from a set of values you can use the IN selector, like this:

$result=$dbh->prepare("SELECT * FROM hire WHERE name IN('item1', 'item2', 'item3')");

Upvotes: 3

Related Questions