简体   繁体   中英

inner join CSV values in string format to MySQL table in php

I have an array of email addresses that I need to verify against a DNC table. Fairly simple in theory- ready for the twist? I cannot make a temp table. Nor do I wish to issue a SELECT statement for each email. Wouldn't it be unsightly to chain 'OR' statements? I would imagine relatively inefficient. Anyone see a clean, efficient way of going about this?

I'm not sure if this answers your question, but you can use "IN" instead of chaining a bunch of "OR" statements.

SELECT *
FROM yourtable
WHERE email IN ('some@email.com', 'another@email.com', 'athird@email.com');

is a much easier way of writing:

SELECT *
FROM yourtable
WHERE (email = 'some@email.com'
   OR email = 'another@email.com'
   OR email = 'athird@email.com');
$q = '
SELECT *
FROM yourtable
WHERE email IN ("'.implode('","', $yourArray).'")
';

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