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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.