trassalg Posted August 29, 2007 Share Posted August 29, 2007 I've got the following code working to retrieve articles from the database and display the results, but they only return one article even since I added the line: AND categories IN ("$categories\") What I'd like to do with this line is use the categories as a filter to select one or various numbered categories, thus displaying various articles on the results page rather than just one result. $fromDate = $_POST['fromDate']; $untilDate = $_POST['untilDate']; $orderby = $_POST['orderby']; if ($categories == "") { $categories = "NULL"; } else { $categories = implode(',', $_POST['categories']); } $query = "SELECT * FROM articleTable WHERE 1=0 OR (articleTitle LIKE \"%$search1%\" OR articleText LIKE \"%$search1%\") AND ((author LIKE \"$author\" AND source LIKE \"$source\") AND categories IN (\"$categories\") AND (dateOfArticle BETWEEN '$fromDate' AND '$untilDate')) ORDER BY 'dateOfArticle' DESC"; Quote Link to comment https://forums.phpfreaks.com/topic/67168-retrieving-multiple-rows-from-database-using-filter/ Share on other sites More sharing options...
fenway Posted August 29, 2007 Share Posted August 29, 2007 Echo the final query string. Quote Link to comment https://forums.phpfreaks.com/topic/67168-retrieving-multiple-rows-from-database-using-filter/#findComment-337247 Share on other sites More sharing options...
trassalg Posted August 29, 2007 Author Share Posted August 29, 2007 The echoed query string is: SELECT * FROM articleTable WHERE 1=0 OR (articleTitle LIKE "% %" OR articleText LIKE "% %") AND ((author LIKE "%" AND source LIKE "%") AND categories IN ("11","2","3","34","42","5") AND (dateOfArticle BETWEEN '2000-01-01' AND '2007-08-29')) ORDER BY 'dateOfArticle' DESC Quote Link to comment https://forums.phpfreaks.com/topic/67168-retrieving-multiple-rows-from-database-using-filter/#findComment-337374 Share on other sites More sharing options...
Illusion Posted August 30, 2007 Share Posted August 30, 2007 It doesn't matter even if u add a filter because 0 * Anything results zero so u have to more look into this part (articleTitle LIKE "% %" OR articleText LIKE "% %") AND ((author LIKE "%" AND source LIKE "%") .If it results FALSE even though there are records satisfying `categories IN ("11","2","3","34","42","5") AND (dateOfArticle BETWEEN '2000-01-01' AND '2007-08-29')) ` it results FALSE. Quote Link to comment https://forums.phpfreaks.com/topic/67168-retrieving-multiple-rows-from-database-using-filter/#findComment-337636 Share on other sites More sharing options...
trassalg Posted August 30, 2007 Author Share Posted August 30, 2007 How would it result false? Every article has a space in it, thus I'm using "% %" as a default search term to make sure results are found. Same with Author and Source fields. What part would result false then? Quote Link to comment https://forums.phpfreaks.com/topic/67168-retrieving-multiple-rows-from-database-using-filter/#findComment-337970 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.