Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Search Function Mod Help Needed

Status
Not open for further replies.

technobia

ISP
Sep 8, 2005
53
US
This was re-posteed in this form by request.


The following is related to a Xoops website. I have posted on that forum with out any replies on over a week. I am not a programmer but I am fully capable of modifying code.

RE: Xoops 2.0.16 running xcGallery 2.03 module

I would like to add pre-selected search terms in a drop down list that user can use to search via selection OR manually enter other keyword criteria in an exiting field that already exists in the code that works.

Because this is an art gallery site. Some of the pre-selectable search terms needed in the drop down list should be things like: Abstract, Landscapes, Photography etc.

I have successfully added the drop down list (see code below) but I do not know how to do the coding to get it to query the DB and display the results just as the normal manual entry keyword search works when clicking the submit search button.

I would like to have the user select something from the list and then click the search button OR once they let go of the selection from the list the search begins automatically. Either one would be fine.

============================================================
<div align="center">
<table border="1" width="400" bordercolor="#1D829C" id="table2" cellpadding="10">
<tr>
<td>

<p align="center">Please enter a search criteria to fulfill your project needs.<br />
You may search by color, style, genre, artist, media, etc.</p>

<form bordercolor="#1D829C" style="margin 0; padding: 0;" method="get" action="thumbnails.php" >
<div bordercolor="#1D829C" align="center">
<table width="400" cellspacing="1" cellpadding="0" style="width: 100%;">
<tr>
<td align="center" class="foot">

BEGIN NON-WORKING CODE

<select size="1" name="search" class="textinput">
<option value="Abstract">Abstract</option>
<option value="Landscape">Landscape</option>
<option value="Photography">Photography</option>
</select>&nbsp;

END NON-WORKING CODE

<input type="input" style="width: 216; height: 22" name="search" maxlength="255" value="" class="textinput" />&nbsp;&nbsp;
<input type="submit" value="Submit Search" class="button" />
</td>
</tr>
</table>
</div>
<input type="hidden" name="type" value="full" />
<input type="hidden" name="album" value="search" />
</form>

</td>
</tr>
</table>
</div>
============================================================

The Search.php file code is as follows:
===========================================================
<?php
include "../../mainfile.php";
define('IN_XCGALLERY', true);

require('include/init.inc.php');
$xoopsOption['template_main'] = 'xcgal_search.html';
include XOOPS_ROOT_PATH."/header.php";
$xoopsTpl->assign('xoops_module_header', $xcgal_module_header);
$xoopsTpl->assign('search_title', _MD_SEARCH_TITLE);
user_save_profile();
$xoopsTpl->assign('gallery', $xoopsModule->getVar('name'));
include_once "include/theme_func.php";
main_menu();
do_footer();
include_once "../../footer.php";

?>
===========================================================
The main.php language file has the following line that refers to the form fields

define("_MD_SEARCH_TITLE","Search the image collection");


I tried adding the following and it breaks the gallery module so I took it out.

define{"_MD_SEARCH_ABSTRACT","Search Collection for Abstract"};

I also tried to add the line:

$xoopsTpl->assign('search_title', _MD_SEARCH_TITLE);

in the above Search.php but that did not work either. I also tried making the Option "value" in the form ="<{$search_abstract}>"
===========================================================

I hope I am being as clear as needed to help

This seems like it should be pretty simple but it is making me pull my hair out as I am on deadline with this project.

Thanks so much! Any assistance will be GREATLY appreciated.
 
Glad to see you posted over here. Now:

Can you show us thumbnails.php? As it seems thats the file
that's actually receiving the form values.

----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Ok Thumnails.php code:

<?php
include "../../mainfile.php";
define('IN_XCGALLERY', true);

require('include/init.inc.php');
$myts =& MyTextSanitizer::getInstance(); // MyTextSanitizer object
function get_subcat_data($parent, &$album_set_array, $level)
{
global $xoopsDB;

$result = $xoopsDB->query("SELECT cid, name, description FROM ".$xoopsDB->prefix("xcgal_categories")." WHERE parent = '$parent'");
if ($xoopsDB->getRowsNum($result) > 0){
$rowset = db_fetch_rowset($result);
foreach ($rowset as $subcat){
$result=$xoopsDB->query("SELECT aid FROM ".$xoopsDB->prefix("xcgal_albums")." WHERE category = {$subcat['cid']}");
$album_count = $xoopsDB->getRowsNum($result);
while($row = $xoopsDB->fetchArray($result)){
$album_set_array[] = $row['aid'];
} // while
}
if ($level > 1) get_subcat_data($subcat['cid'], $album_set_array, $level -1);
}
}

/**************************************************************************
* Main code
**************************************************************************/

if (isset($_GET['sort'])) $USER['sort'] = $_GET['sort'];
if (isset($_GET['cat'])) $cat = $_GET['cat'];
if (isset($_GET['search'])){
$USER['search'] = $_GET['search'];
if (isset($_GET['type']) && $_GET['type'] == 'full') {
$USER['search'] = '###'.$USER['search'];
}
}
if (isset($_GET['suid'])){
$USER['suid'] = $_GET['suid'];
}
$album = $_GET['album'];

if (isset($_GET['page'])){
$page = max((int)$_GET['page'], 1);
} else {
$page = 1;
}

$breadcrumb = '';
$breadcrumb_text = '';
$cat_data = array();

// Build the private album set
if (!GALLERY_ADMIN_MODE && $xoopsModuleConfig['allow_private_albums']) get_private_album_set();

if (is_numeric($album)){
$result = $xoopsDB->query("SELECT category, title FROM ".$xoopsDB->prefix("xcgal_albums")." WHERE aid='$album' $ALBUM_SET");
if ($xoopsDB->getRowsNum($result)>0) {
$CURRENT_ALBUM_DATA = $xoopsDB->fetchArray($result);
$actual_cat = $CURRENT_ALBUM_DATA['category'];
breadcrumb($actual_cat, $breadcrumb, $breadcrumb_text);
$cat = -$album;
} else redirect_header("index.php", 3, _NOPERM);
} elseif (isset($cat) && $cat) { // Meta albums, we need to restrict the albums to the current category
if ($cat < 0) {
$result = $xoopsDB->query("SELECT category, title FROM ".$xoopsDB->prefix("xcgal_albums")." WHERE aid='".(-$cat)."'");
if ($xoopsDB->getRowsNum($result)>0) {
$CURRENT_ALBUM_DATA = $xoopsDB->fetchArray($result);
$actual_cat = $CURRENT_ALBUM_DATA['category'];
$CURRENT_CAT_NAME = $myts->makeTboxData4Show($CURRENT_ALBUM_DATA['title']);
}
$ALBUM_SET .= 'AND aid IN ('.(-$cat).') ';
breadcrumb($actual_cat, $breadcrumb, $breadcrumb_text);
} else {
$album_set_array = array();
if ($cat == USER_GAL_CAT)
$where = 'category > '.FIRST_USER_CAT;
else
$where = "category = '$cat'";

$result=$xoopsDB->query("SELECT aid FROM ".$xoopsDB->prefix("xcgal_albums")." WHERE $where");
while($row = $xoopsDB->fetchArray($result)){
$album_set_array[] = $row['aid'];
} // while
if ($cat >= FIRST_USER_CAT) {
$user_handler =& xoops_gethandler('member');
$alb_owner =& $user_handler->getUser($cat-FIRST_USER_CAT);
if (is_object ($alb_owner)) $CURRENT_CAT_NAME = sprintf(_MD_INDEX_USERS_GAL, $alb_owner->uname());
else redirect_header('index.php',2,_MD_NO_EXIST_CAT);

} else {
$result = $xoopsDB->query("SELECT name FROM ".$xoopsDB->prefix("xcgal_categories")." WHERE cid = '".$cat."'");
if ($xoopsDB->getRowsNum($result) == 0) redirect_header('index.php',2,_MD_NO_EXIST_CAT);
$row = $xoopsDB->fetchArray($result);
$CURRENT_CAT_NAME = $myts->makeTboxData4Show($row['name']);
}
get_subcat_data($cat, $album_set_array, $xoopsModuleConfig['subcat_level']);

// Treat the album set
if (count($album_set_array)) {
$set ='';
foreach ($album_set_array as $album_id) $set .= ($set == '') ? $album_id : ','.$album_id;
$ALBUM_SET .= "AND aid IN ($set) ";
}

breadcrumb($cat, $breadcrumb, $breadcrumb_text);
}
}

$xoopsOption['template_main'] = 'xcgal_index.html';
include XOOPS_ROOT_PATH."/header.php";
$xoopsTpl->assign('xoops_module_header', $xcgal_module_header);
$xoopsTpl->assign('display_alb_list','');
user_save_profile();
include_once "include/theme_func.php";
if ($breadcrumb) theme_display_cat_list($breadcrumb, $cat_data, '');
else {
$xoopsTpl->assign('breadcrumb', '<a href="index.php">'.$xoopsModule->getVar('name').'</a>');
$xoopsTpl->assign('lang_category',0);
$xoopsTpl->assign('set_stat',0);
}
display_thumbnails($album, (isset($cat) ? $cat : 0), $page, $xoopsModuleConfig['thumbcols'], $xoopsModuleConfig['thumbrows'], true);

$xoopsTpl->assign('gallery', $xoopsModule->getVar('name'));

main_menu();
do_footer();
include_once "../../footer.php";
?>
 
I agree with vacunita: thumnails.php is where at least the start of the mischief is.

but to add flavour i would also suggest that you disable the select control if there is any text in the override text box you are providing. don't do this on the server side (by ignoring input) (well, do do it but not only on the server side) as otherwise the user interface may confuse people into believing that the search criteria is an OR or an AND rather than a singleton.

 
Error #1: You can't have 2 form elements with the samew name:
Code:
 <select size="1" [red]name="search"[/red] class="textinput">
       <option value="Abstract">Abstract</option>
       <option value="Landscape">Landscape</option>
       <option value="Photography">Photography</option>
       </select>&nbsp;

and 
 <input type="input" style="width: 216; height: 22" [red]name="search"[/red] maxlength="255" value="" class="textinput" />

So name your select box a different thing.

Then I believe the part to be modified should be this one:

Code:
if (isset($_GET['search'])){
        $USER['search'] = $_GET['search'];
        if (isset($_GET['type']) && $_GET['type'] == 'full') {
            $USER['search'] = '###'.$USER['search'];
        }
}


Add a new IF section where search is changed to the nameofselectbox.

Code:
if (isset($_GET['[red]nameofselectbox[/red]'])){
        $USER['search'] = $_GET['[red]nameofselectbox[/red]'];
        if (isset($_GET['type']) && $_GET['type'] == 'full') {
            $USER['search'] = '###'.$USER['search'];
        }
}


I agree with jpadie, that if there is something selected in the dropdown box, then you should disable the textbox, to avoid confusion.

A simple JS OnChang event can do that. But first test it out, see if it works like that.






----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top