Building a Simple Search Engine with PHP
Subject:   A more detailed query...
Date:   2003-12-23 06:52:17
From:   anonymous2
Hi Daniel,

Thanks again for your fantastic tutorial. I was wondering how one might submit a query which exclueds certain words and includes others. I know that the following should work for finding several words:

$result = mysql_query(" SELECT p.page_url AS url,
COUNT(*) AS occurrences
FROM page p, word w1, occurrence o1, word w2, occurrence o2
WHERE p.page_id = o1.page_id AND
w1.word_id = o1.word_id AND
w1.word_word = \"$keyword[1]\" AND
w2.word_id = o2.word_id AND
w2.word_word = \"$keyword[2]\" AND
GROUP BY p.page_id
ORDER BY occurrences DESC
LIMIT $results" );

But how can I also tell it to NOT provide me with an article that contains a word I don't want as well?

- Giff

Main Topics Oldest First

Showing messages 1 through 2 of 2.

  • A more detailed query...
    2003-12-23 22:43:15  anonymous2 [View]

    Hi Giff

    Thank you for that. However, there is still a minor defect. This is what came up when i pasted your code in. And keep in mind that i have not altered anything stated in the article.

    "Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /var/www/html/jeo/dev/search/search.php on line 48
    query executed in 0.000 seconds."

    So does anyone have a suggestion?
    Please help!

    Thank you all for helping me so far.

    Best wishes for the festive season!

  • RE: A more detailed query...
    2003-12-23 07:15:55  dsolin [View]

    Hi Giff,

    I'm not sure if I got you right here, but couldn't you just use the != or NOT LIKE operators? This would result in something like:

    w2.word_word != \"$keyword[1]\"


    w2.word_word NOT LIKE \"$keyword[1]\"

    Hope that helps!