#1
  1. Contributing User
    SEO Chat Explorer (0 - 99 posts)

    Join Date
    Jun 2003
    Location
    Romania
    Posts
    89
    Rep Power
    16

    Advanced search PHP and MySQL problem


    I want to order the records displayed in a search by there relevance. I have made a formula but every time I enter a PHP function in the query string no records are returned.
    I have tried something like:

    select id, nume, vizualizari, url, descriere, categorie, subcategorie, limba, subtr_count(url,"word1")*3 +subtr_count(nume,"word1")*2 + subtr_count(descriere,"word1") + subtr_count(url,"word2")*3 +subtr_count(nume,"word2")*2 + subtr_count(descriere,"word2") AS weight from siteuri WHERE (weight>0) ORDER BY weight desc

    or

    select id, nume, vizualizari, url, descriere, categorie, subcategorie, limba, subtr_count(url,"word1")*3 +subtr_count(nume,"word1")*2 + subtr_count(descriere,"word1") + subtr_count(url,"word2")*3 +subtr_count(nume,"word2")*2 + subtr_count(descriere,"word2") AS weight from siteuri WHERE ((nume LIKE '%word1%' OR descriere LIKE '%word1%' OR url LIKE '%word1%') AND (nume LIKE '%word2%' OR descriere LIKE '%word2%' OR url LIKE '%word2%')) ORDER BY weight desc

    Thank you
  2. #2
  3. No Profile Picture
    JRM
    Contributing User
    SEO Chat Discoverer (100 - 499 posts)

    Join Date
    Jul 2003
    Posts
    108
    Rep Power
    16
    Is there any errors? It looks like you may have some errors, using a php function in the query.

    Have you ever tried to use fulltext in MYSQL?
    look it up on the mysql site.

    If you do you can do your query something like this:

    select id, nume, vizualizari, url, descriere, categorie, subcategorie, limba,
    MATCH (nume,descriere.url)
    AGAINST ('$word1') + MATCH (nume,descriere.url)
    AGAINST ('$word2') AS weight from siteuri

    WHERE MATCH (nume,descriere.url)
    AGAINST ('$word1') + MATCH (nume,descriere.url)
    AGAINST ('$word2') and weight>0 ORDER BY weight desc
  4. #3
  5. Contributing User
    SEO Chat Explorer (0 - 99 posts)

    Join Date
    Jun 2003
    Location
    Romania
    Posts
    89
    Rep Power
    16
    I know about the full text indexing in mysql but I want to give more weigh to some fields.
    Thank you anyway.
    It seams that if I use a php function in the query no records are returned. I have seen examples saying it can be done, maybe I am missing something.
  6. #4
  7. No Profile Picture
    Registered User
    SEO Chat Explorer (0 - 99 posts)

    Join Date
    Oct 2010
    Location
    Poland
    Posts
    1
    Rep Power
    0

    Dance in Krakow


    Hello folks. I think it is specially forum. Welcome to kurs tanca Krakow

IMN logo majestic logo threadwatch logo seochat tools logo