Let me elaborate I put the wildcard character % in SQL statement it show results for some mispelled words but not for all for targeted search (formed by 2 or more words in does give any results), and the pagination code doesn' t work i.e. the function responsible doesn' t display any results although the SQL statement is correct and no errors expect a notice (Undefined index) for the variable in which I put page number.
I have read the some (there were a lot of them) of the other posts on these matters but none provided me with a good answer.
Code: Select all
//variables
$valid=false;
//number of the page
$nrp=1;
//results shown
$show=10;
//current page
$nrc=0;
//number of rows in the query
$nrt=0;
//search term
$term='';
$urm='';
$leg="";
$sir="SELECT TABLE1.COLUMN1, TABLE2.COLUMN2, Table2.COLUMN3 FROM TABLE1 INNER JOIN TABLE2 ON Cid1=Cid2";
if($_GET['page']==''){$pag=1;}
//verifing if the search button was pushed and the search term is correct
if(!isset($_GET["Search"]) || $valid==false)
{
header( "Expires: Mon, 20 Dec 2006 01:00:00 GMT" );
header( "Last-Modified: " .gmdate("D, d M Y H:i:s") . " GMT" );
header( "Cache-Control: no-cache, must-revalidate" );
header( "Pragma: no-cache" );
?>
<form method='GET' action='<?php echo $_SERVER['PHP_SELF']?>'>
<table>
<tr>
<td>The term which you want to search.<td>
<td><input type='text' name='term' /><input type='submit' name='Search' value='Search' /></td>
<!-- <td></td> -->
</tr>
<?php
}
//after a succesfull validation
if ($valid==true)
{
$termen=addslashes($_GET['term']);
//validate
$sir=$sir ." WHERE Column1 LIKE '%" .$term ."%' OR Column2 LIKE '%" .$term ."%' OR Column3 LIKE '%". $term."%' ";
//count the results of the query
$nrt=countRows($sir);
echo $nrt;
$nrp=ceil($nrt/$shown);
echo $nrp;
if ($nrt==0)
{
echo "<h2>The term searched isn' t in our database</h2>";
}
else
{
for ($i=0; $i<$nrp; $i++)
{
if($pag==$i) { $urm="<a href='search.php?page=" .$i . "'><strong>" .$i ."</strong></a>"; }
else
{
//the function that echo the results
selection($sir,$nrp);
$urm .="<a href='search.php?page=" .$pag ."'>" .$i ."</a>";
}
}
}
//the function selection
function selectie($s="", $n=0)
{
$r='';
$matAfis='';
$show=10;
$s=$s ." LIMIT " .(($n*$show)- $show) .", " .$show;
$r=mysql_query($s) or die (mysql_error());
while($r2=mysql_fetch_array($r))
{
echo "\t\t <tr>\r";
echo "\t\t\t <td>" ."<a href='url1'>" .$r2['Column1'] ."</a>" ."</td>\r";
echo "\t\t\t <td>" ."<a href='url2'>" .$r2["Column2"] ."</a>" ."</td>\r";
echo "\t\t</tr>\r";
}
}