/    Sign up×
Community /Pin to ProfileBookmark

multiple mysql column search

If I have a database including these columns:
‘subject1′,’subject2′,’subject3′,’subject4′,’subject5′,’subject6′,’subject7′,’subject8′,’subject9′,’subject10′,’subject11’

Is there an easy way to say

Select * FROM table WHERE story like ‘%foo%’ AND NAME = ‘Bob’ ……..
And then have at the end:
if (‘subject1′,’subject2’……subject11’) contains ‘bar’

Thank you

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@MindzaiJan 26.2010 — Yu could do it with loads of OR conditions, but your table screams out for normalization. It would make for far simpler queries, and make you app much more flexible.
Copy linkTweet thisAlerts:
@qforeverJan 27.2010 — Mindzai right. Normalization seems required. But you may use something like this:

[CODE]$wharr=array();
for($i=1;$i<12;$i++) {
$wharr[]="subject".$i." LIKE '&#37;bar%'"
}

$your_query=".... (".implode(" OR ",$wharr).")...";[/CODE]
Copy linkTweet thisAlerts:
@happyeddieauthorJan 27.2010 — Thank you to you both. Have managed to get it to work with your suggestions.
×

Success!

Help @happyeddie spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.6,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...