Jump to content

Advanced Search


doddsey_65

Recommended Posts

Im building an advanced search feature and its mostly going fine. The only problem is that results are displayed more times than they need to be.

 

I have a test post in the database:

 

p_name                                          p_content

Testing Advanced Search                This is to test the advanced search

 

When i do a search with the keywords "testing advanced search" and set it to match any keywords it does bring up this post as it should do. But it is displaying it 3 times when there is only one instance of it in the database. here is my code:

 

$match = $_POST['match']; // for this example match === any
$keywords = $_POST['keywords']; // for this example keywords === testing advanced search
$within = $_POST['within']; // for this example within === p_c (post_content only)

switch($within)
{
    case 'p_s_c':
    default:
        $sql_match = 'p.p_name, p.p_content';
        break;
    case 'p_c':
        $sql_match = 'p.p_content';
        break;
    case 'p_s':
        $sql_match = 'p.p_name';
        break;
    case 't_t':
        $sql_match = 't.t_name';
        break;
}

$match === 'all' ? $keywords = '"'.$keywords.'"' : $keywords = $keywords;

$query = $link->query("SELECT p.*, t.* 
            FROM ".TBL_PREFIX."posts as p
            JOIN ".TBL_PREFIX."topics as t
            WHERE MATCH ($sql_match) AGAINST('$keywords' IN BOOLEAN MODE)")
            or die(print_link_error());
while($row = $query->fetch(PDO::FETCH_ASSOC))
{
    $return = preg_split('|, |', $sql_match);
    for($i=0; $i<count($return); $i++)
    {
        $return[$i] = substr($return[$i], 2);
        echo '<p>Results: '.$row[$return[$i]].'</p>';
    }
}

 

And here is the echoed query:

 

SELECT p.*, t.* FROM asf_posts as p JOIN asf_topics as t WHERE MATCH (p.p_content) AGAINST('Testing advanced search' IN BOOLEAN MODE)

 

Any help?

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.