Hello,
I have a gallery with lots of pictures. I want users to be able to search albums and categories aswell as pictures. I've previously used "Search Album v1.08" by paver, however the search time can go up to 1 minute+ when i use this.
I've came up with a solution however i am not experienced enough to pull it off so i wonder if anyone could help me fit these 2 codes together on one page.
The first search code is simply taken from the original "Search.php" by Gaugau which is included in the coppermine root. (slightly modded on the buttons)
<?php
/*************************
Coppermine Photo Gallery
************************
Copyright (c) 2003-2007 Coppermine Dev Team
v1.1 originally written by Gregory DEMAR
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
********************************************
Coppermine version: 1.4.12
$Source$
$Revision: 3636 $
$Author: gaugau $
$Date: 2007-06-29 11:35:30 +0200 (Fr, 29 Jun 2007) $
**********************************************/
define('IN_COPPERMINE', true);
define('SEARCH_PHP', true);
require('include/init.inc.php');
if (!USER_ID && $CONFIG['allow_unlogged_access'] == 0) {
$redirect = $redirect . "login.php";
header("Location: $redirect");
exit();
}
pageheader($lang_search_php['title']);
echo <<< EOT
<form method="post" action="thumbnails.php" name="searchcpg">
EOT;
starttable('60%', $lang_search_php['title']);
$ip = GALLERY_ADMIN_MODE ? '
<tr>
<td>
<input type="checkbox" name="pic_raw_ip" class="checkbox" id="pic_raw_ip" /><label for="pic_raw_ip" class="clickable_option">'.$lang_search_php['ip_address'].'</label>
</td>
</tr>' :
'<tr>
<td> </td>
<td> </td>
</tr>';
$customs = '';
$result = cpg_db_query("SELECT * FROM {$CONFIG['TABLE_CONFIG']} WHERE name LIKE 'user_field%_name' AND value <> '' ORDER BY name ASC");
while ($row = mysql_fetch_assoc($result)){
$name = str_replace(array('_field', '_name'), '', $row['name']);
$customs .= <<< EOT
<tr>
<td><input type="checkbox" name="$name" id="$name" class="checkbox" /><label for="$name" class="clickable_option">{$row['value']}</label></td>
</tr>
EOT;
}
echo <<< EOT
<tr>
<td class="tableb" align="center" >
<input type="text" style="width: 80%" name="search" maxlength="255" value="" class="textinput" />
<input type="submit" value="{$lang_search_php['submit_search']}" class="button" />
<input type="hidden" name="album" value="search" />
</td>
</tr>
<tr>
<td class="tableb">
<table align="center" width="60%">
<tr>
<td>{$lang_search_php['fields']}:</td>
<td align="center">{$lang_search_php['age']}:</td>
</tr>
<tr>
<td><input type="checkbox" name="title" id="title" class="checkbox" checked="checked" /><label for="title" class="clickable_option">{$lang_adv_opts['title']}</label></td>
<td align="right">{$lang_search_php['newer_than']} <input type="text" name="newer_than" size="3" maxlength="4" class="textinput" /> {$lang_search_php['days']}</td>
</tr>
<tr>
<td><input type="checkbox" name="caption" id="caption" class="checkbox" checked="checked" /><label for="caption" class="clickable_option">{$lang_adv_opts['caption']}</label></td>
<td align="right">{$lang_search_php['older_than']} <input type="text" name="older_than" size="3" maxlength="4" class="textinput" /> {$lang_search_php['days']}</td>
</tr>
<tr>
<td><input type="checkbox" name="filename" id="filename" class="checkbox" checked="checked" /><label for="filename" class="clickable_option">{$lang_adv_opts['filename']}</label></td>
<td> </td>
</tr>
<tr>
<td><input type="checkbox" name="owner_name" id="owner_name" class="checkbox" /><label for="owner_name" class="clickable_option">{$lang_adv_opts['owner_name']}</label></td>
<td align="right"><select name="type" class="listbox">
<option value="AND" selected="selected">{$lang_search_php['all_words']}</option>
<option value="OR">{$lang_search_php['any_words']}</option></select>
</td>
</tr>
</table>
</td>
</tr>
EOT;
endtable();
echo '</form>';
if ($CONFIG['clickable_keyword_search'] != 0) {
include('include/keyword.inc.php');
}
echo <<< EOT
<script language="javascript" type="text/javascript">
<!--
document.searchcpg.search.focus();
-->
</script>
EOT;
pagefooter();
ob_end_flush();
?>
What i would like to integrate into this code is Abbas Ali's code to search for categories & albums (really fast one!)
?php
// ------------------------------------------------------------------------- //
// Coppermine Photo Gallery 1.3.0 miniCMS //
// ------------------------------------------------------------------------- //
// Copyright (C) 2004 Tarique Sani <tarique@sanisoft.com>, //
// Amit Badkas <amit@sanisoft.com> //
// http://www.chezgreg.net/coppermine/ //
// ------------------------------------------------------------------------- //
// This program is free software; you can redistribute it and/or modify //
// it under the terms of the GNU General Public License as published by //
// the Free Software Foundation; either version 2 of the License, or //
// (at your option) any later version. //
// ------------------------------------------------------------------------- //
// ------------------------------------------------------------------------- //
// Search modification by Kum Sackey //
// ------------------------------------------------------------------------- //
define('IN_COPPERMINE', true);
define('EDITPICS_PHP', true);
require('include/init.inc.php');
pageheader("Category Search");
printf("<center>");
starttable("100%", "Category Search" , 3);
?>
<?php
#class='tableborder'
while (list($name, $value) = each($HTTP_GET_VARS)) {
# echo "$name = $value<br>\n";
if ($name == "query" ) $query = $value;
}
while (list($name, $value) = each($HTTP_GET_VARS)) {
echo "$name = $value<br>\n";
}
?>
<?php
$query = $_GET['query'];
$query_pieces = explode(" ", $query);
$query = "";
$c = 0;
$cd = 0;
while ($c < count($query_pieces) )
{
if ($query_pieces[$c] != "")
{
if (strlen($query_pieces[$c]) < 3)
{
$query_discard[$cd] = $query_pieces[$c];
$cd = $cd + 1;
}
else
{
$query .= '%'.$query_pieces[$c];
}
}
$c = $c + 1;
}
$query .= '%';
// echo $query;
if ($query != '%' )
{
$result = cpg_db_query("SELECT * FROM `{$CONFIG['TABLE_CATEGORIES']}` WHERE `name` LIKE '$query'");
$result2 = cpg_db_query("SELECT * FROM `{$CONFIG['TABLE_ALBUMS']}` WHERE `title` LIKE '$query'");
}
?>
<tr>
<td class="tableb" > <div align="center">
<table width="75%" cellspacing="2" cellpadding="2">
<tr>
<td> <p>This tool searches category and album titles for all the whitespace
seperated words you input.</p>
<p>For a search word to be valid, it must contain at least three characters.</p>
<p>Enter search terms:</p>
<form name="form1" method="get" action="<?php echo $PHP_SELF?>" >
<p>
<input type="text" name="query">
<input type="submit" name="Submit" value="Submit">
</p>
</form></td>
</tr>
</table>
<p> </p>
<h2>Search Results</h2>
<?
if ($cd > 0)
{
echo 'The following search terms were discarded because they were too short: ';
$c = 0;
while ($c < ($cd - 1) )
{
echo $query_discard[$c].',';
$c = $c + 1;
}
echo $query_discard[$c];
echo '<br>';
}
?>
<?php if (mysql_num_rows($result) + mysql_num_rows($result2) == 0)
{ echo "No results found"; }
else
{
?>
<table width="75%" border="1" cellpadding="2" cellspacing="2">
<tr>
<td colspan="2" class="tableh1">Categories</td>
</tr>
<?php
// Output Data into Table
while ($cat_list = mysql_fetch_array($result, MYSQL_ASSOC))
{
?>
<tr>
<td> <a href="<?php printf("index.php?cat=%u", $cat_list['cid']); ?> ">
<?php echo $cat_list['name']; ?> </a></td>
<td>
<?php if ($cat_list['description'] == "") { echo ' '; }else { echo $cat_list['description']; } ?>
</td>
</tr>
<?php
}
?>
<tr>
<td colspan="2" class="tableh1">Albums</td>
</tr>
<?php
// Output Data into Table
while ($alb_list = mysql_fetch_array($result2, MYSQL_ASSOC))
{
?>
<tr>
<td><a href="<?php printf("thumbnails.php?album=%u", $alb_list['aid']); ?> ">
<?php echo $alb_list['title']; ?> </a></td>
<td>
<?php if ($alb_list['description'] == "") { echo ' '; }else { echo $alb_list['description']; } ?>
</td>
</tr>
<?php
}
?>
</table>
<?php
}
?>
</div></td>
</tr>
<?php
printf("</center>");
endtable();
?>?php
// ------------------------------------------------------------------------- //
// Coppermine Photo Gallery 1.3.0 miniCMS //
// ------------------------------------------------------------------------- //
// Copyright (C) 2004 Tarique Sani <tarique@sanisoft.com>, //
// Amit Badkas <amit@sanisoft.com> //
// http://www.chezgreg.net/coppermine/ //
// ------------------------------------------------------------------------- //
// This program is free software; you can redistribute it and/or modify //
// it under the terms of the GNU General Public License as published by //
// the Free Software Foundation; either version 2 of the License, or //
// (at your option) any later version. //
// ------------------------------------------------------------------------- //
// ------------------------------------------------------------------------- //
// Search modification by Kum Sackey //
// ------------------------------------------------------------------------- //
define('IN_COPPERMINE', true);
define('EDITPICS_PHP', true);
require('include/init.inc.php');
pageheader("Category Search");
printf("<center>");
starttable("100%", "Category Search" , 3);
?>
<?php
#class='tableborder'
while (list($name, $value) = each($HTTP_GET_VARS)) {
# echo "$name = $value<br>\n";
if ($name == "query" ) $query = $value;
}
while (list($name, $value) = each($HTTP_GET_VARS)) {
echo "$name = $value<br>\n";
}
?>
<?php
$query = $_GET['query'];
$query_pieces = explode(" ", $query);
$query = "";
$c = 0;
$cd = 0;
while ($c < count($query_pieces) )
{
if ($query_pieces[$c] != "")
{
if (strlen($query_pieces[$c]) < 3)
{
$query_discard[$cd] = $query_pieces[$c];
$cd = $cd + 1;
}
else
{
$query .= '%'.$query_pieces[$c];
}
}
$c = $c + 1;
}
$query .= '%';
// echo $query;
if ($query != '%' )
{
$result = cpg_db_query("SELECT * FROM `{$CONFIG['TABLE_CATEGORIES']}` WHERE `name` LIKE '$query'");
$result2 = cpg_db_query("SELECT * FROM `{$CONFIG['TABLE_ALBUMS']}` WHERE `title` LIKE '$query'");
}
?>
<tr>
<td class="tableb" > <div align="center">
<table width="75%" cellspacing="2" cellpadding="2">
<tr>
<td> <p>This tool searches category and album titles for all the whitespace
seperated words you input.</p>
<p>For a search word to be valid, it must contain at least three characters.</p>
<p>Enter search terms:</p>
<form name="form1" method="get" action="<?php echo $PHP_SELF?>" >
<p>
<input type="text" name="query">
<input type="submit" name="Submit" value="Submit">
</p>
</form></td>
</tr>
</table>
<p> </p>
<h2>Search Results</h2>
<?
if ($cd > 0)
{
echo 'The following search terms were discarded because they were too short: ';
$c = 0;
while ($c < ($cd - 1) )
{
echo $query_discard[$c].',';
$c = $c + 1;
}
echo $query_discard[$c];
echo '<br>';
}
?>
<?php if (mysql_num_rows($result) + mysql_num_rows($result2) == 0)
{ echo "No results found"; }
else
{
?>
<table width="75%" border="1" cellpadding="2" cellspacing="2">
<tr>
<td colspan="2" class="tableh1">Categories</td>
</tr>
<?php
// Output Data into Table
while ($cat_list = mysql_fetch_array($result, MYSQL_ASSOC))
{
?>
<tr>
<td> <a href="<?php printf("index.php?cat=%u", $cat_list['cid']); ?> ">
<?php echo $cat_list['name']; ?> </a></td>
<td>
<?php if ($cat_list['description'] == "") { echo ' '; }else { echo $cat_list['description']; } ?>
</td>
</tr>
<?php
}
?>
<tr>
<td colspan="2" class="tableh1">Albums</td>
</tr>
<?php
// Output Data into Table
while ($alb_list = mysql_fetch_array($result2, MYSQL_ASSOC))
{
?>
<tr>
<td><a href="<?php printf("thumbnails.php?album=%u", $alb_list['aid']); ?> ">
<?php echo $alb_list['title']; ?> </a></td>
<td>
<?php if ($alb_list['description'] == "") { echo ' '; }else { echo $alb_list['description']; } ?>
</td>
</tr>
<?php
}
?>
</table>
<?php
}
?>
</div></td>
</tr>
<?php
printf("</center>");
endtable();
?>
Each of these create a table where you can put in what you're looking for and click " search " however i would like to have both on the same page so i don't have to make 2 search buttons for my gallery.
If this isn't possible, can you give me and tips on other solutions that might be more simple to do with gives me almost the same result?
Thank you in advance.