/    Sign up×
Community /Pin to ProfileBookmark

query problem

Hi

For some reason the below query is not omitting the rows that has the value Delete in the column status

thank you for any help

[code=php]
$query_sql_get_ads = (“SELECT * FROM ads WHERE status != ‘Delete’ title LIKE ‘%$search%’ OR category LIKE ‘%$search%’ OR sub_category LIKE ‘%$search%’ order by $sortBy desc LIMIT $start, $end”);
[/code]

to post a comment
PHP

5 Comments(s)

Copy linkTweet thisAlerts:
@homer_j_simpsonMar 18.2007 — [code=php]
$query_sql_get_ads = ("SELECT * FROM ads WHERE status != 'Delete' title LIKE '%$search%' OR category LIKE '%$search%' OR sub_category LIKE '%$search%' order by $sortBy desc LIMIT $start, $end");
[/code]

I think u forgot 'AND' keyword between status field and title field.
Copy linkTweet thisAlerts:
@kprocauthorMar 18.2007 — yeh I made the found that but it made no difference

[code=php]
$query_sql_get_ads = ("SELECT * FROM ads WHERE title LIKE '%$search%' OR category LIKE '%$search%' OR sub_category LIKE '%$search%' AND status = 'Delete' order by $sortBy desc LIMIT $start, $end");
$sql_get_ads = mysql_query($query_sql_get_ads)or die("SQL Error: $query_sql_get_ads<br>" . mysql_error());

[/code]
Copy linkTweet thisAlerts:
@NanscombeMar 18.2007 — Hi kproc,

I believe your problem is being caused by not putting brackets around the OR statements.

It was like saying "Where Title or Category or (Sub-Category AND Not delete)" rather than "Where (Title or Category or Sub-Category) AND Not delete"

Try the following:

[code=php]
$query_sql_get_ads = ("SELECT * FROM ads WHERE (title LIKE '%$search%' OR category LIKE '%$search%' OR sub_category LIKE '%$search%') AND status != 'Delete' order by $sortBy desc LIMIT $start, $end");
$sql_get_ads = mysql_query($query_sql_get_ads)or die("SQL Error: $query_sql_get_ads<br>" . mysql_error());
[/code]


Regards

Nigel
Copy linkTweet thisAlerts:
@kprocauthorMar 18.2007 — thank you for the reply that worked excellent and I learned something new
Copy linkTweet thisAlerts:
@NightShift58Mar 19.2007 — A "like" query is usually what takes the longest. What you want to do is to put all the "easy" K.O. criteria up front in your query and only have the "like" execute when necessary, as follows:[code=php]
$query_sql_get_ads = "
SELECT * FROM ads
WHERE status != 'Delete'
AND (title LIKE '%$search%'
OR category LIKE '%$search%'
OR sub_category LIKE '%$search%')
ORDER BY $sortBy DESC LIMIT $start, $end
";
$sql_get_ads = mysql_query($query_sql_get_ads)or die("SQL Error: $query_sql_get_ads<br>" . mysql_error()); [/code]
×

Success!

Help @kproc 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.27,
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,
)...