Need help in this.

Discussion in 'PHP' started by balasun, Aug 13, 2008.

  1. #1
    Hello all,

    Please Help me in the below works,

    I want to search process in non-case sensitive manner and highlight the search keyword in red font in also non case sensitive manner. But it does not wors properly.The highlight does not made for some keywords and some result comes not related with the keyword.

    My coding is as follows.

    if(isset($_REQUEST[txtSearch]))
    	{
    	 $t=$_REQUEST[txtSearch];  //keyword for search 
    	 $searchtxt=stripslashes(strtolower($_REQUEST[txtSearch]));
    	 $searchtxt1=stripslashes(strtoupper($_REQUEST[txtSearch]));
    	//$searchtxt1=addslashes(htmlspecialchars($searchtxt));
    	//echo $searchtxt1=addslashes(htmlspecialchars($searchtxt));
       $sql="SELECT * FROM page_content  WHERE (modelno LIKE '%$searchtxt%') or (modelno LIKE '%$searchtxt1%') or (prodname LIKE '%$searchtxt%') or (prodname LIKE '%$searchtxt1%') or (proddesc LIKE '%$searchtxt%') or (proddesc LIKE '%$searchtxt1%') or (prodfeature LIKE '%$searchtxt%') or (prodfeature LIKE '%$searchtxt1%') or (prodspec LIKE '%$searchtxt%') or (prodspec LIKE '%$searchtxt1%')";
    	$res=mysql_query(getPagingQuery($sql))or die(mysql_error());
    	$num=mysql_num_rows($res);
    	$i=1;
    	if($num!=0)
    	{
    	while($row=$db->fetch_array($res))
    	{
    	
    	$pname=stripslashes($pname);
    	$pdesc=stripslashes($row[proddesc]);
    	 $t1=strtolower($t);
    //for Highlight operation
    	 $pdesc1=str_replace($t1,"<b><font color=red>".$t1."</font></b>",$pdesc);
    	 $t2=strtoupper($t1);
    	 $pdesc2=str_replace($t2,"<b><font color=red>".$t2."</font></b>",$pdesc1);
    	// $pdesc2=str_replace($t,"<b><font color=red>".$t."</font></b>",$pdesc1);
    	 //$pdesc2=str_replace($searchtxt,"<b><font color=red>".$searchtxt."</font></b>",$pdesc1);
    	echo "<p align='justify'><a href=getcontent.php?mcid=$row[mcid]&scid=$row[scid]><font size='2'><u>$i.$row[modelno].&nbsp;$pname</u></font></a></span><br/><br>$pdesc2<br/></p>";
    	$i=$i+1;
    	}
    	}
    PHP:
    Please Help me if u know the answer.
     
    balasun, Aug 13, 2008 IP
  2. minibuck

    minibuck Peon

    Messages:
    32
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    minibuck, Aug 14, 2008 IP