Thank you for your help.
I have removed the previous header() and changed the code a bit but still on the final header() (the only one now) I get the error
'Warning: Cannot modify header information - headers already sent by (output started at'
which references the following on 133
echo $dbterm." : ".$any." : ".$all."<br>";
the new code
<?php
/*
Displaying the search page
Created: 13th September 2007
*/
/* if a match on all search words failed to produce a result, we can try a match on any word by setting the flag below*/
$allow_wider_search = true;
/*if we're trying a wider search and it returns more results than the value below, we'll ignore the results as they will be too non-specific. */
$max_wider_search_results = 50;
/* limit the number of results returned by the query*/
$max_results = '100';
$sortby = 'price';
$sortreverse = false;
if ($_GET["search"]!=null){
$term = $_GET["search"];
}
if ($_POST["search"]!=null){
$term = $_POST["search"];
}
if ($_GET["search2"]!=null){
$term = $_GET["search2"];
}
if ($_POST["search2"]!=null){
$term = $_POST["search2"];
}
$min = 0;
if ($_POST["min"]!=null){
$min = $_POST["min"];
}
if ($_GET["min"]!=null){
$min = $_GET["min"];
}
$max=100000;
if ($_POST["max"]!=null){
$max = $_POST["max"];
}
if ($_GET["max"]!=null){
$max = $_GET["max"];
}
$search_query = $term;
if (ereg("^search/.*$",$page_query))
{
$results_exist=0;
if ($_GET["qterm"]!=null){
$qterm = $_GET["qterm"];
$followed = code_id($_GET["link"]);
//record search selection, then follow link.
$rs = mysql_query("select IFNULL((concat(replace(followedlist,'".$followed."',''),',".$followed."')), '".$followed."')
from store_searchhistory where searchterm='".$qterm."'");
if (mysql_num_rows($rs)){
$followedlist = mysql_result($rs, 0, 0);
if (substr($followedlist, 0, 1) == ",") $followedlist = substr($followedlist,1); //remove a csv comma if at start
mysql_query("update store_searchhistory set followedlist='".$followedlist."' where searchterm='".$qterm."'");
//header("Location:/".id_code($followed));
//header("Location: /".id_code($followed));
$str1 = id_code($followed);
}
}
if (strlen($term) > 0){
$dbterm="";
$rs = mysql_query("select manufacturer as x from store_manufacturers where manufacturer = '".$term."'
union
select ifnull(
(select (concat(ou.reference,'/', midl.reference, '/', inn.reference)) as x from store_categories as ou
join store_categories as midl on ou.category_id = midl.category_parent
join store_categories as inn on midl.category_id = inn.category_parent
where inn.category like '".$term."%')
,(select ifnull((select (concat(ou.reference,'/', inn.reference)) as x from store_categories as ou
join store_categories as inn on ou.category_id = inn.category_parent
where inn.category like '".$term."%')
,(select (reference) as x from store_categories
where category like '".$term."%')
) as x))as x");
if (mysql_num_rows($rs)){
$manufacturer = mysql_result($rs, 0, 0);
$manufacturer = eregi_replace("[^0-9a-z_/]","_",$manufacturer);
$manufacturer = eregi_replace("[_]+","_",$manufacturer);
$str2 = $manufacturer."/";
//header('"Location:/".$manufacturer."/"', false);
}
$exact="";
$any="";
$term = str_replace('\"','"', $term);
if(ereg('("[A-Za-z0-9/& ]+")', $term, $regs)){
$exact = $regs[1];
$term = str_replace($exact, '', $term);
}
$term = ereg_replace(' +',' ', $term); //remove extra spaces
//
$rs=mysql_query("select replace((select group_concat(searchterm) from(select searchterm from store_thesaurus as sa where uid in (
select uid from store_thesaurus where link1 in(
select link1 from store_thesaurus where match searchterm against ('".$term."' in boolean mode)
) )
union select manufacturer as searchterm from store_manufacturers as sm
where match manufacturer against ('".$term."' in boolean mode)) as any),',',' ') as x");
if (mysql_num_rows($rs)){
$indiv_term = split(" ",$term);
$any = mysql_result($rs,0,0);
$any_term = split(" ",$any);
$term2 = $term;
if ($any != null){
foreach ($indiv_term as $indiv){
foreach ($any_term as $anystr){
//remove found alternatives from search string
$teststr = $indiv;
if (strtolower($anystr) == strtolower($teststr)) $term2 = str_replace($teststr, '', $term2);
}
}
}
$all = ereg_replace('([A-Za-z0-9]+)', '+\\1', $term2); //add '+' before each search term that doesn't have a leading character (e.g. quote)
$dbterm = $any." ".$all." ".$exact;
}
else {
$dbterm = ereg_replace('([A-Za-z0-9]+)', '+\\1', $term)." ".$exact;
}
echo $dbterm." : ".$any." : ".$all."<br>";
$rs=runSearch($exact, $any, $term, $dbterm);
if (mysql_num_rows($rs)) $results_exist=1;
else{
if ($allow_wider_search){
$rs=runSearch($exact, $any, $term, $any." ".$term2." ".$exact);
if (mysql_num_rows($rs) & (mysql_num_rows($rs) < $max_wider_search_results)) $results_exist=2;
}
}
echo $results_exist;
if (mysql_num_rows($rs)==1)
{
$str3 = id_code(mysql_result($rs, 0, 'product_id'));
header("location: $str3", false);
}
}
}
//header("Location: /".id_code($followed));
//header('"Location:/".$manufacturer."/"', false);
//Header("Location:/".id_code(mysql_result($rs, 0, 'product_id')));
//$str1 = id_code($followed);
//$str3
function runSearch($exact, $any, $term, $dbterm) //$exact is quoted values, $any are non prefixed values, $term is original search term, $dbterm is parsed searchterm
{
return mysql_query("
select sp1.*, sm.manufacturer as m_name, scat.category as c_name from store_products as sp1
left join
store_manufacturers as sm
on sm.manufacturer_id = sp1.manufacturer
left join
store_categories as scat
on scat.category_id = sp1.category
where product_id in(
select product_id from store_products where match (product_name) against (
'".$dbterm."'
in boolean mode
)
union
select product_id from store_products where manufacturer_code like (CONCAT('".$term."', '%'))
union
select product_id from store_products where product_code like (CONCAT('".$term."', '%'))
)and product_name like ('%')
and sm.manufacturer like(CONCAT((ifnull(
(select manufacturer from store_manufacturers where match (manufacturer) AGAINST('".str_replace('"','',$exact)." ".$any."' in boolean mode) limit 1), '')
),'%')
)
and scat.category like(CONCAT((IFNULL(
(select category from store_categories where category LIKE '".str_replace('"','',$exact)."' limit 1), '')
),'%')
)
LIMIT 100 ;");
}
function recordSearch($searchterm, $resultlist){
$rs = mysql_query("select (searchcount + 1) from store_searchhistory where searchterm='".$searchterm."' LIMIT 1");
if (mysql_num_rows($rs)){
mysql_query("update store_searchhistory set searchcount='".mysql_result($rs, 0, 0)."'
, resultlist='".$resultlist."'
, timestamp=now() where searchterm='".$searchterm."'");
}
else{
mysql_query("insert into store_searchhistory (searchterm, searchcount, resultlist, timestamp)
values('".$searchterm."',1, '".$resultlist."', now())");
}
}
?>