Not sure if this has been posted but I couldn't find it find it in the forum so I made this using the example from
http://www.w3schools.com/php/php_ajax_livesearch.aspwith a different modification to have an Ajax Live Search for the Albums on my website
http://www.ehmongmusic.comyou should see the search feature in the Artist and Album Search section
file you will need to make
anycontent.php // save in root of coppermine
<?php
/*************************
Coppermine Photo Gallery
************************
Copyright (c) 2003-2006 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.10
$Source$
$Revision: 3275 $
$Author: gaugau $
$Date: 2006-09-03 12:10:47 +0200 (So, 03 Sep 2006) $
**********************************************/
/**
* Coppermine Photo Gallery 1.4.10 anycontent.php
*
* This file file gets included in the index.php if you set the option in admin
* can be used to display any content from any program, it is always to be edited
* according to tastes and then used
*
* @copyright 2002,2005 Gregory DEMAR, Coppermine Dev Team
* @license http://opensource.org/licenses/gpl-license.php GNU General Public License V2
* @package Coppermine
* @version $Id: anycontent.php 3275 2006-09-03 10:10:47Z gaugau $
*/
if (!defined('IN_COPPERMINE')) die('Not in Coppermine...');
starttable("100%", "Anycontent");
?>
<tr><td class="tableb" >
<form>
<p>Enter a name you want to search: </p>
<input type="text" id="txt1" size="90"
onkeyup="showResult(this.value)">
<div id="livesearch"></div>
</form>
</td></tr>
<?php
endtable();
?>
livesearch.js // save in root of coppermine
var xmlHttp
function showResult(str)
{
if (str.length==0)
{
document.getElementById("livesearch").
innerHTML="";
document.getElementById("livesearch").
style.border="0px";
return
}
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
{
alert ("Browser does not support HTTP Request")
return
}
var url="livesearch.php"
url=url+"?q="+str
url=url+"&sid="+Math.random()
xmlHttp.onreadystatechange=stateChanged
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
}
function stateChanged()
{
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{
document.getElementById("livesearch").
innerHTML=xmlHttp.responseText;
document.getElementById("livesearch").
style.border="1px solid #A5ACB2";
}
}
function GetXmlHttpObject()
{
var xmlHttp=null;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
// Internet Explorer
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp;
}
livesearch.php // save in root of coppermine
<?php
define('IN_COPPERMINE', true);
define('LOGIN_PHP', true);
require('include/init.inc.php');
$q=$_GET["q"];
if (strlen($q) > 0)
{
$hint = "";
$searchword = explode(" ", $q);
for( $i = 0; $i < sizeof($searchword); $i++ ){
$searchword[$i] = "title LIKE '%" .$searchword[$i]. "%'";
//echo $searchword[$i] . "\n";
}
$ready = implode(" AND ", $searchword);
//echo $ready;
$result = cpg_db_query("SELECT aid, title FROM {$CONFIG['TABLE_ALBUMS']} WHERE $ready");
while ($row = mysql_fetch_array($result)) {
if ( $hint == "" ){
$hint = '<a href="thumbnails.php?album='. $row['aid'] .'">'. $row['title'] . '</a>';
}
else{
$hint = $hint . '<br /><a href="thumbnails.php?album='. $row['aid'] .'">'. $row['title'] . '</a>';
}
}
mysql_free_result($result);
}
// Set output to "no suggestion" if no hint were found
// or to the correct values
if ($hint == ""){
$response = "Try short one word name and then go from there";
}
else{
$response = $hint;
}
//output the response
echo $response;
?>
plus add these codes
<style type="text/css">
#livesearch
{
margin:0px;
width:75%;
}
#txt1
{
margin:0px;
}
</style>
<script src="livesearch.js"></script>
before the </head> section of your theme template.html
It seem useful for my site anyways hope it is useful for yours too.
I have about 400+ albums and the search seems like of slow if you guys that know php can help make it faster I would appreciate that.
Don't forget to add "anycontent" to the "The content of the main page" in config
Hopefully that is everything.
PS: I don't know where to post, so I post it here instead.