Guest_imported
New member
- Jan 1, 1970
- 0
Hi, I was wondering if you could help me with the following code. It's carried out from a form where the user inputs the text to search in an input box called "search" and there's two options to search by "name" or "description" which are radio buttons with the name request and the values "name" and "description" respectively.
The variable $limit is set to 15 through a config file. It's not my original code so I've tried editing it with no success. My trouble was that I don't know what the variable $operateur comes from or what it does.
The unexpected results i'm receiving is that some times when you search it just comes up blank when correct informatio is inputted. The limit links don't appear either so It only displays 15 results. I would also like it to arrange the results by the name. You can test the script at
I'd be very greatful for your help. Thanx
<?
$db = mysql_connect($host,$login,$pass);
mysql_select_db($base,$db);
if (!isset($debut)) $debut = 0;
if (!empty($search))
{
$search=strtolower($search);
$mots = str_replace( "+", " ", trim($search));
$mots = str_replace( "\"", " ", $mots);
$mots = str_replace( ",", " ", $mots);
$mots = str_replace( ":", " ", $mots);
$search=rawurlencode($search);
$tab=explode( " " , $mots);
$nb=count($tab);
$sql= "SELECT * FROM bands_tbl WHERE 1 and $request like \"%$tab[0]%\" ";
for($i=1 ; $i<$nb; $i++)
{
$sql.= "$operateur $request like \"%$tab[$i]%\" ";
}
$sql2=$sql;
$sql.= " Limit $debut,$limit ";
$result2 = mysql_db_query($base,$sql2);
$result = mysql_db_query($base,$sql);
if($result)
{
$nrows = mysql_num_rows($result2);
$flag = 1;
if(mysql_num_rows($result)==0) echo '<center><font face="Verdana" size="2"><b>No result</b></font></center>';
else
{
$nb=1;
while($data = mysql_fetch_array($result)) {
echo '<p align="left" style="margin-bottom: 5"><font face="Verdana" size="2"><img border="0" src="../images/lnav_5.gif" width="12" height="8"><a href="'.$data['site'].'" target="_blank">
<b>'.$data['name'].'</b></a></font></b></p>';
}
$nombre=ceil($nb/$limit);
echo "<center>"; if($debut>0)
{
echo "<font face=\"Verdana\" size=\"1\"><a href=search.php?search=$search&operateur=$operateur&debut=".($debut-$limit). "><<</a> </font> ";
}
if ($nombre>1)
{ for($i=1; $i<=$nombre; $i++)
{
echo "<font face=\"Verdana\" size=\"1\"><a href=search.php?search=$search&operateur=$operateur&debut=".(($i-1)*$limit). ">".$i. "</a> </font> ";
}
}
if(($debut+$limit)<$nb)
{
echo "<font face=\"Verdana\" size=\"1\"><a href=search.php?search=$search&operateur=$operateur&debut=".($debut+$limit). ">>></a></font>";
}
echo "</CENTER>";
}
}
}
else
{
echo( "<center><br><b><font face=\"Verdana\" size=\"2\">You have to enter at least one word</font></b></center>"
}
mysql_close($db);
?>
The variable $limit is set to 15 through a config file. It's not my original code so I've tried editing it with no success. My trouble was that I don't know what the variable $operateur comes from or what it does.
The unexpected results i'm receiving is that some times when you search it just comes up blank when correct informatio is inputted. The limit links don't appear either so It only displays 15 results. I would also like it to arrange the results by the name. You can test the script at
I'd be very greatful for your help. Thanx
<?
$db = mysql_connect($host,$login,$pass);
mysql_select_db($base,$db);
if (!isset($debut)) $debut = 0;
if (!empty($search))
{
$search=strtolower($search);
$mots = str_replace( "+", " ", trim($search));
$mots = str_replace( "\"", " ", $mots);
$mots = str_replace( ",", " ", $mots);
$mots = str_replace( ":", " ", $mots);
$search=rawurlencode($search);
$tab=explode( " " , $mots);
$nb=count($tab);
$sql= "SELECT * FROM bands_tbl WHERE 1 and $request like \"%$tab[0]%\" ";
for($i=1 ; $i<$nb; $i++)
{
$sql.= "$operateur $request like \"%$tab[$i]%\" ";
}
$sql2=$sql;
$sql.= " Limit $debut,$limit ";
$result2 = mysql_db_query($base,$sql2);
$result = mysql_db_query($base,$sql);
if($result)
{
$nrows = mysql_num_rows($result2);
$flag = 1;
if(mysql_num_rows($result)==0) echo '<center><font face="Verdana" size="2"><b>No result</b></font></center>';
else
{
$nb=1;
while($data = mysql_fetch_array($result)) {
echo '<p align="left" style="margin-bottom: 5"><font face="Verdana" size="2"><img border="0" src="../images/lnav_5.gif" width="12" height="8"><a href="'.$data['site'].'" target="_blank">
<b>'.$data['name'].'</b></a></font></b></p>';
}
$nombre=ceil($nb/$limit);
echo "<center>"; if($debut>0)
{
echo "<font face=\"Verdana\" size=\"1\"><a href=search.php?search=$search&operateur=$operateur&debut=".($debut-$limit). "><<</a> </font> ";
}
if ($nombre>1)
{ for($i=1; $i<=$nombre; $i++)
{
echo "<font face=\"Verdana\" size=\"1\"><a href=search.php?search=$search&operateur=$operateur&debut=".(($i-1)*$limit). ">".$i. "</a> </font> ";
}
}
if(($debut+$limit)<$nb)
{
echo "<font face=\"Verdana\" size=\"1\"><a href=search.php?search=$search&operateur=$operateur&debut=".($debut+$limit). ">>></a></font>";
}
echo "</CENTER>";
}
}
}
else
{
echo( "<center><br><b><font face=\"Verdana\" size=\"2\">You have to enter at least one word</font></b></center>"
}
mysql_close($db);
?>