/    Sign up×
Community /Pin to ProfileBookmark

Exclude rows from search based on a value in a field

I have a basic search page that queries the database and displays results based on the search term. I have an “approved” field that is set to 0 by default. When the user searches, I would like to exclude rows that have the “approved” field set to 0.

Here’s what I have now:

[code=php]$q =”SELECT * FROM tablename WHERE name LIKE ‘%” . $searchterm . “%'”; [/code]

Still new to PHP/MySQL, so please bear with me if this is childs play stuff ?

Thanks in advance!

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@bruisrauthorNov 03.2011 — I searched a bit differently and found the answer:
[code=php]$q ="SELECT * FROM tablename WHERE name LIKE '%" . $searchterm . "%' AND approved != '0'"; [/code]

This kept the unapproved rows out of the search results. Hope this helps anyone else who comes across it.
×

Success!

Help @bruisr 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.29,
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,
)...