https://www.icyphoenix.com/viewtopic.php?f=26&t=1296
-----------------------------------
dilirum
Sun 11 Mar, 2007 03:07

FAP CUSTOMIZATION - FAP Search Multiple Fields
-----------------------------------
I've been looking for a way to do this for awhile now. Searched many phpbb boards and mightygordon boards. 

Current search system has a drop down box to search either username, picture title or description. I'd like to perform a search and return results for all those fields at once (well probably not username, but at least title and description). I'm not a php expert but can stumble my way around. I tried a few different things (mainly hard coding a search function) but I can't get it to search more than one field without erroring out with a "Bad Request" message.

Any ideas on how to implement this? Can't imagine it would be too intensive. Thanks in advance for any ideas anybody can give me in the right direction.


-----------------------------------
Mighty Gorgon
Sun 11 Mar, 2007 14:15

Re: FAP Search Multiple Fields
-----------------------------------
[quote user="dilirum" post="9871"]I've been looking for a way to do this for awhile now. Searched many phpbb boards and mightygordon boards. 

Current search system has a drop down box to search either username, picture title or description. I'd like to perform a search and return results for all those fields at once (well probably not username, but at least title and description). I'm not a php expert but can stumble my way around. I tried a few different things (mainly hard coding a search function) but I can't get it to search more than one field without erroring out with a "Bad Request" message.

Any ideas on how to implement this? Can't imagine it would be too intensive. Thanks in advance for any ideas anybody can give me in the right direction.[/quote]
At the moment I have no time...

I'll try to do it when I have some free time... but maybe Lefty or Artie will have a play too. :mri:


-----------------------------------
dilirum
Mon 12 Mar, 2007 09:35

Re: FAP Search Multiple Fields
-----------------------------------
Thanks for the reply. 

Anyone?


-----------------------------------
dilirum
Tue 20 Mar, 2007 04:05

Re: FAP Search Multiple Fields
-----------------------------------
Main reason i'm looking for this is to search from outside phpBB. I want to have an HTML form where users can enter a keyword then use a drop down box to search "album, forum, etc." including other pages on my site. But I really don't want it to be "album description, album title, forum, etc." Just too many options there. Want to keep it simple and use search album to automatically search both fields. 

Anybody have any idea on how to get the search function to search both fields?


-----------------------------------
Mighty Gorgon
Thu 22 Mar, 2007 01:56

Re: FAP Search Multiple Fields
-----------------------------------
I gues you could have a try modifying album_search.php in some way like this...

[code]AND (p.pic_desc LIKE '%" . $s . "%' OR p.pic_title LIKE '%" . $s . "%' OR p.pic_username LIKE '%" . $s . "%')[/code]

Have a try and let me know...


-----------------------------------
dilirum
Thu 22 Mar, 2007 19:51

Re: FAP Search Multiple Fields
-----------------------------------
Gorgon, 

Thanks for the help but I'm really not sure where to put that. I'm not that great with PHP, just basically stumble my way around. Sorry.

I played with my album_search.php but it doesn't seem to work anyplace I try to insert tha, but again, I'm not sure of what I'm doing.


-----------------------------------
Artie
Fri 23 Mar, 2007 01:27

Re: FAP Search Multiple Fields
-----------------------------------
This may get you close to what you're lookin for.

[code linenumbers=false]

#
## ---- [ OPEN ] -------------------------------------------------------------------------------------------
#
includes/page_header.php
#
## ---- [ FIND ] ----------------------------------------------------------------------------------------------
#
'L_DESCRIPTION' => $lang['Description'],
#
## ---- [ AFTER ADD ] ------------
#
'L_TITLE_DESCRIPTION' => $lang['Title_Description'],
	
#
## ---- [ OPEN ] ------------------------------------------------------------------------------------------
#
language/lang_english/lang_main.php
#
## ---- [ FIND ] ------------
#
$lang['Description'] = 'Description';
#
## ---- [ AFTER ADD ] -----------------------------------------------------------------------------------
#
$lang['Title_Description'] = 'Title & Description';

#
## ---- [ OPEN ] ------------
#
album_search.php
#
## ---- [ FIND ] -------------------------------------------------------------------------------------------
#
if ($m == 'user')
	{
		$where = 'p.pic_username';
	}
	elseif ($m == 'name')
	{
		$where = 'p.pic_title';
	}
	elseif ($m == 'desc')
	{
		$where = 'p.pic_desc';
	}
	else
	{
		message_die(GENERAL_ERROR, 'Bad request');
	}
#
## ---- [ REPLACE WITH ] ----------------------------------------------------------------------------------------
#
		if ($m == 'user')
	{
  	$where =	"AND p.pic_username LIKE '%" . $s . "%'";
	}
	elseif ($m == 'name')
	{
	   $where =	"AND p.pic_title LIKE '%" . $s . "%'";
	}
	elseif ($m == 'desc')
	{
	   $where =	"AND p.pic_desc LIKE '%" . $s . "%'";
	}
  elseif ($m == 'title_desc')
	{
		$where = "AND (p.pic_desc LIKE '%" . $s . "%' OR p.pic_title LIKE '%" . $s . "%')";
	}
	else
	{
		message_die(GENERAL_ERROR, 'Bad request');
	}	
#
## ---- [ FIND ] -------------------------------------------------------------------------------------------------------------
#
$count_sql = "SELECT COUNT(pic_id) AS count
								FROM " . ALBUM_TABLE . ' AS p,' . ALBUM_CAT_TABLE . " AS c
								WHERE p.pic_approval = 1
								AND " . $where .  " LIKE '%" . $s . "%'
								" . $search_pg . "
								AND p.pic_cat_id = c.cat_id";
#
## ---- [ REPLACE WITH ] ---------------------------------------------------------------------------------------------------
#
$count_sql = "SELECT COUNT(pic_id) AS count
								FROM " . ALBUM_TABLE . ' AS p,' . ALBUM_CAT_TABLE . " AS c
								WHERE p.pic_approval = 1
								" . $where .  $search_pg . "
								AND p.pic_cat_id = c.cat_id";                
#
## ---- [ FIND ] ------------------------------------------------------------------------------------------------------------------
#
$sql = "SELECT p.pic_id, p.pic_title, p.pic_desc, p.pic_user_id, p.pic_username, p.pic_time, p.pic_cat_id, p.pic_approval, c.cat_id, c.cat_title, c.cat_user_id
			FROM " . ALBUM_TABLE . ' AS p,' . ALBUM_CAT_TABLE . " AS c
			WHERE p.pic_approval = 1
				AND " . $where .  " LIKE '%" . $s . "%'
				AND p.pic_cat_id = c.cat_id
				" . $search_pg . "
			ORDER BY p.pic_time DESC LIMIT ".$limit_sql."";
#
## ---- [ REPLACE WITH ] ---------------------------------------------------------------------------------------------------------------
#
$sql = "SELECT p.pic_id, p.pic_title, p.pic_desc, p.pic_user_id, p.pic_username, p.pic_time, p.pic_cat_id, p.pic_approval, c.cat_id, c.cat_title, c.cat_user_id
			FROM " . ALBUM_TABLE . ' AS p,' . ALBUM_CAT_TABLE . " AS c
			WHERE p.pic_approval = 1
				" . $where .  "
				AND p.pic_cat_id = c.cat_id
				" . $search_pg . "
			ORDER BY p.pic_time DESC LIMIT ".$limit_sql."";
      
#
## ---- [ OPEN ] ------------
# (each of these 8 template files)
templates/subSilver/album_cat_body.tpl
templates/subSilver/album_comment_body.tpl
templates/subSilver/album_index_body.tpl
templates/subSilver/album_memberlist_body.tpl
templates/subSilver/album_personal_body.tpl
templates/subSilver/album_personal_index_body.tpl
templates/subSilver/album_search_body.tpl
templates/subSilver/album_showpage_body.tpl
#
## ---- [ FIND] ------------
#
	<option value="desc">{L_DESCRIPTION}</option>
#
## ---- [ AFTER ADD ] -----------------------------------------------------------------------
#
	<option value="title_desc">{L_TITLE_DESCRIPTION}</option>	
#
## ---- [ SAVE FILES ] ------------------------------------------------------------------------
#	Eom


[/code]


-----------------------------------
dilirum
Fri 23 Mar, 2007 09:21

Re: FAP Search Multiple Fields
-----------------------------------
[b]Artie[/b], That friggin rocks! It works like a champ! I was beginning to think that it might be too complicated to conjure something up, but here you come and just bust it out like it's nuthin!

Thanks Artie! You rock! I owe ya' one!  :mryellow:


-----------------------------------
Artie
Fri 23 Mar, 2007 16:56

Re: FAP Search Multiple Fields
-----------------------------------
[quote user="dilirum" post="10616"].... but here you come and just bust it out like it's nuthin!
[/quote]
Would be nuthin for MG, but for me it requires some effort :icy_lol_flag:

Anyway, you are welcome. :wink:


-----------------------------------
Mighty Gorgon
Tue 27 Mar, 2007 01:33

Re: FAP Search Multiple Fields
-----------------------------------
[quote user="Artie" post="10643"]Would be nuthin for MG, but for me it requires some effort :icy_lol_flag:

Anyway, you are welcome. :wink:[/quote]
It requires some effort for me as well... :wink:

Anyway... added to standard FAP. :wink:

Thanks.


