MySQL Forums
Forum List  »  Newbie

Conditions order in query
Posted by: rpaccard
Date: June 15, 2005 10:40AM

The following code doesn't give me the expected results. I believe I must have an error in the query, possibly in its logics or is it a matter of precedence.


if ($q_category == "any")
{
$cond1 = "mag_toc.category LIKE '%%'";
}
else
{
$cond1 = "mag_toc.category = '$q_category'";
}

if ($q_journalist == "any")
{
$cond2 = "mag_toc.journalist LIKE '%%'";
}
else
{
$cond2 = "mag_toc.journalist = '$q_journalist'";
}

$query = " SELECT mag_toc.id AS toc_id, id_issue, date_archive, title, category, journalist, magazine.id, magazine.date_issue
FROM mag_toc, magazine
WHERE
CURDATE() >= date_archive
AND magazine.id = mag_toc.id_issue
AND
(
(mag_toc.title LIKE '%$q%' OR mag_toc.description LIKE '%$q%' OR mag_toc.body LIKE '%$q%')
AND (mag_toc.id_issue >= '$q_id_issue1' AND mag_toc.id_issue <= '$q_id_issue2')
AND $cond1
AND $cond2
)
ORDER BY title";

Options: ReplyQuote


Subject
Written By
Posted
Conditions order in query
June 15, 2005 10:40AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.