Jump to content

Retrieving multiple rows from database using filter


trassalg

Recommended Posts

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";

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

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.