SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Zealot pnathan's Avatar
    Join Date
    Sep 2001
    Location
    Amsterdam
    Posts
    160
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    mySQL search results

    I currently have my PHP page, searching my mySQL database and returning the list of search results. No problems.

    I am struggling with the next step. Obviously, I want the user to see which is the best search result and list the results from the best down, rather then the order they were entered in the database.

    So what I want to do is: list the search results in order of the most relevant topic to the search and preferably, have a rating for each search result.

    Any ideas?
    I have two tickets to the Crows, sweet.

  2. #2
    Mlle. Ledoyen silver trophy seanf's Avatar
    Join Date
    Jan 2001
    Location
    UK
    Posts
    7,168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Have you looked at Full-text searching?
    http://www.mysql.com/doc/F/u/Fulltext_Search.html

    Sean
    Harry Potter

    -- You lived inside my world so softly
    -- Protected only by the kindness of your nature

  3. #3
    SitePoint Zealot pnathan's Avatar
    Join Date
    Sep 2001
    Location
    Amsterdam
    Posts
    160
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Seanf, thanks for that. I have implemented the changes but I am getting an error. Here is my code:

    PHP Code:
    <? 
    $query 
    mysql_query("SELECT * FROM $usertable WHERE MATCH (solution) AGAINST ('%$search%')"); 
    ?> 
    <table border=1 cellspacing=0 cellpadding=4 width=500 bgcolor=#CCCC99 bordercolor=#CCCC99 bordercolorlight=#CCCC99 bordercolordark=#CCCC99>
    <tr>
    <td width=20 class=SUBPAGE bgcolor=#FFFFFF><b>ID</b></td>
       <td width=400 class=SUBPAGE bgcolor=#FFFFFF><b>Description of Problem</b></td>
    </tr>
    <?php
    while ($row  =  mysql_fetch_array($query)) {
       
    extract($row);
    ?> 
    <tr>
       <td width=20 class=SUBPAGE bgcolor=#FFFFFF valign=top><?= $ID ?></td>
       <td width=400 class=SUBPAGE bgcolor=#FFFFFF><a href=http://www.capeclear.com/support/cases/solutions/cases.php?ID=<?= $ID ?>><?= $problem ?></a></td>
    </tr>
    <?php
    }
    ?>
    </table>
    Here is the error I get:
    PHP Code:
    WarningSupplied argument is not a valid MySQL result resource in /result.php3 on line 88 
    Line 88 is:
    PHP Code:
    while ($row  =  mysql_fetch_array($query)) { 
    Any ideas?
    I have two tickets to the Crows, sweet.

  4. #4
    SitePoint Zealot pnathan's Avatar
    Join Date
    Sep 2001
    Location
    Amsterdam
    Posts
    160
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I got it working, this code displays the search results in asscending order.

    PHP Code:
    <? 
    $query 
    mysql_query("SELECT * FROM $usertable WHERE solution LIKE '%$search%' ORDER BY solution ASC"); 
    ?> 
    <table border=1 cellspacing=0 cellpadding=4 width=500 bgcolor=#CCCC99 bordercolor=#CCCC99 bordercolorlight=#CCCC99 bordercolordark=#CCCC99>
    <tr>
    <td width=20 class=SUBPAGE bgcolor=#FFFFFF><b>ID</b></td>
       <td width=400 class=SUBPAGE bgcolor=#FFFFFF><b>Description of Problem</b></td>
    </tr>
    <?php
    while ($row  =  mysql_fetch_array($query)) {
       
    extract($row);
    ?> 
    <tr>
       <td width=20 class=SUBPAGE bgcolor=#FFFFFF valign=top><?= $ID ?></td>
       <td width=400 class=SUBPAGE bgcolor=#FFFFFF><a href=http://www.capeclear.com/support/cases/solutions/cases.php?ID=<?= $ID ?>><?= $problem ?></a></td>
    </tr>
    <?php
    }
    ?>
    All I had to do was add:

    ORDER BY solution ASC

    It is still not the best solution, but it is good enough for my users.
    I have two tickets to the Crows, sweet.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •