Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By markusd1984 on
Can somebody help please adjusting a D6 patch for a D7 ported Module?
It's to include an advanced query that also searches through detailed questions.
I would like this D7 query:
<?php
// $Id: faq_search.find.inc,v 1.1.2.1 2009/09/08 18:11:50 johnpv Exp $
/**
* @file
* Performs the database query based on the supplied keywords.
*/
function faq_search_find() {
$term = strip_tags(drupal_substr($_POST['keyword'], 0, 100));
$query = "SELECT question,nid
FROM {faq_questions}
WHERE question LIKE '%%%s%%'
ORDER BY question asc";
$result = db_query($query, $term);
$string = "";
while ($row = db_fetch_object($result)) {
$string .= "<a href='/". drupal_get_path_alias('node/'. $row->nid)."'>". $row->question ."</a>";
}
if ( empty($string) ) {
$string = t("<p class='message'>No matches!</p>");
}
echo $string;
exit;
}
to incorporate the changes from D6 patch below, for an advanced query
@@ -8,11 +8,15 @@
function faq_search_find() {
$term = strip_tags(drupal_substr($_POST['keyword'], 0, 100));
- $query = "SELECT question,nid
- FROM {faq_questions}
- WHERE question LIKE '%%%s%%'
- ORDER BY question asc";
- $result = db_query($query, $term);
+ $query = "SELECT DISTINCT fq.question, fq.nid
+ FROM {faq_questions} AS fq,
+ {node_revisions} AS f
+ WHERE fq.question LIKE '%%%s%%'
+ OR fq.detailed_question LIKE '%%%s%%'
+ OR f.body LIKE '%%%s%%'
+ AND f.nid = fq.nid
+ AND f.vid = fq.vid
+ ORDER BY fq.question asc";
+ $result = db_query($query, $term, $term, $term);
$string = "";
while ($row = db_fetch_object($result)) {
@@ -26,4 +30,4 @@ function faq_search_find() {
echo $string;
exit;
-}
\ No newline at end of file
+}
I tried it manually but unfortunately didn't work. I came across an error re string vs array i think