PDA

View Full Version : mySQL Multiple Select from name field



Zaid_W1red
June 16th, 2005, 10:29 AM
Im SURE this is a really simple problem but what ever syntax I try i just cant get what i want.

Basically, I have a mySQL table, and i want to select variouse rows based on the email address...in a mix of english and roughly guessed SQL would read:

SELECT * FROM table WHERE email= 'someone', 'someone else', 'somemore'

Returning in this case three rows...

I hope thsi makes sence, id really appreciate it if ANYONE can help!

bwh2
June 16th, 2005, 12:13 PM
try:


$emails = array ( "email1@email.com", "email2@email.com", "email3@email.com" );
foreach ( $emails as $val )
{
$result = mysql_query( "SELECT * FROM table WHERE email='$val'" );
// now do what you want with the result
}

Enigmatic
June 16th, 2005, 12:15 PM
SELECT * FROM table WHERE email = 'someone' OR 'someone else' OR 'something else';

Zaid_W1red
June 17th, 2005, 08:54 AM
Thanks guys...enigmatic, i tried your OR based stament and it would only return the first or option in one row.

If its useful to anyone i siply used enigmatic's code with ||'s replacing the "OR's" and it works great!