PunBB Resource

Your ultimate PunBB resource!

Keywords:

    (Extended)

You are not logged in.

#1 2009-06-23 10:32:05

jaason
Member
From: Poland
Registered: 2008-11-26
Posts: 29
Website

How extend search script?

Hi
I have some problems with extending search.php to find some more things.
I have add new column to pun_posts table and a <select> button with some <option> inside...
therefore I want to search forum for topics which are marked in that column...
how can I do that?

I've add this lines after 278 line in search.php

Code:

/ If it's a search for posts by a specific color
            if ($color)
            {
                switch ($db_type)
                {
                    case 'pgsql':
                        $result = $db->query('SELECT id FROM '.$db->prefix.'posts WHERE color = \''.$color.'\'') or error('Unable to fetch color', __FILE__, __LINE__, $db->error());
                        break;

                    default:
                        $result = $db->query('SELECT id FROM '.$db->prefix.'posts WHERE color = \''.$color.'\'') or error('Unable to fetch color', __FILE__, __LINE__, $db->error());
                        break;
                }

                if ($db->num_rows($result))
                {

                    while ($row = $db->fetch_row($result))

                    $search_ids = array();
                    while ($row = $db->fetch_row($result))
                        $search_ids[] = $row[0];
                        //echo $search_ids;
                        //echo $row;
                    $db->free_result($result);

                }
            }

but it's not working.

Last edited by jaason (2009-06-23 10:33:16)

Offline

 

#2 2009-06-23 22:00:47

Koos
Administrator
Registered: 2007-01-14
Posts: 524
Website

Re: How extend search script?

I have done something similar before. Try the following:

Code:

#
#---------[ 1. OPEN ]---------------------------------------------------------
#

search.php


#
#---------[ 2. FIND ]---------------------------------------------
#

            // If it's a search for author name (and that author name isn't Guest)
            if ($author && strcasecmp($author, 'Guest') && strcasecmp($author, $lang_common['Guest']))
            {
                ...
                ...
            }


#
#---------[ 3. AFTER, ADD ]---------------------------------------------------
#

            // If it's a search for posts by a specific color
            if ($color)
            {
                $result = $db->query('SELECT id FROM '.$db->prefix.'posts WHERE color = \''.$color.'\'') or error('Unable to fetch color', __FILE__, __LINE__, $db->error());

                $search_ids = array();
                $color_results = array();
                while ($row = $db->fetch_row($result))
                    $color_results[] = $row[0];

                $db->free_result($result);
            }


#
#---------[ 4. FIND ]---------------------------------------------
#

            if ($author && $keywords)
            {
                // If we searched for both keywords and author name we want the intersection between the results
                $search_ids = array_intersect($keyword_results, $author_results);
                unset($keyword_results, $author_results);
            }
            else if ($keywords)
                $search_ids = $keyword_results;
            else
                $search_ids = $author_results;


#
#---------[ 5. AFTER, ADD ]---------------------------------------------------
#

            if ($color)
            {
                if (!empty($search_ids))
                {
                    // If we searched for color we want the intersection between the results
                    $search_ids = array_intersect($search_ids, $color_results);
                    unset($color_results);
                }
                else
                    $search_ids = $color_results;
            }

Update: I've simplified the code above a bit.

Last edited by Koos (2009-06-24 11:30:25)

Offline

 

#3 2009-06-24 12:27:15

jaason
Member
From: Poland
Registered: 2008-11-26
Posts: 29
Website

Re: How extend search script?

who else but Koos ;d
looks very complicated but it works ;d
big thanks!!!

Last edited by jaason (2009-06-24 12:33:23)

Offline

 

Board footer

Based on PunBB
© Copyright 2002–2005 Rickard Andersson

© Copyright 2004–2006 Kristoffer Jansson

User contributed files are property of their respective owners.