Help me to do this

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

  1. #1
    Hello all,

    I need ur help in below work,

    I need to made search operation depending upon keywords typed in the text box, and also in results i highlighted with red the search keywords. The problem in this is the search keywords are highlighted with case sensitive. That is, when i type 'html' to search, in the result 'HTML' is not highlighted.

    I need to highlighted the result with an incase sensitive keyword.

    My coding is as follows:

    $searchtxt=stripslashes($_REQUEST[txtSearch]);
    	//$searchtxt1=addslashes(htmlspecialchars($searchtxt));
    	//echo $searchtxt1=addslashes(htmlspecialchars($searchtxt));
       $sql="SELECT * FROM page_content  WHERE (modelno LIKE '%$searchtxt%') or (prodname LIKE '%$searchtxt%') or (proddesc LIKE '%$searchtxt%') or (prodfeature LIKE '%$searchtxt%') or (prodspec LIKE '%$searchtxt%')";
    	$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]);
    	 $pdesc=str_replace($t,"<b><font color=red>".$searchtxt."</font></b>",$pdesc);
    	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>$pdesc<br/></p>";
    	$i=$i+1;
    	}
    PHP:
    Please help me if u know the answer
     
    balasun, Aug 4, 2008 IP
  2. rob_v

    rob_v Peon

    Messages:
    72
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #2
    change the where to be where (lower(modelno) like.....
    and the same w/ the rest of the wheres
     
    rob_v, Aug 4, 2008 IP
  3. rob_v

    rob_v Peon

    Messages:
    72
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #3
    to add to that - make sure that $searchtxt is already lower

    $searchtxt=stripslashes($_REQUEST[txtSearch]);
    make
    $searchtxt=strtolower(stripslashes($_REQUEST[txtSearch]));
     
    rob_v, Aug 4, 2008 IP
  4. balasun

    balasun Peon

    Messages:
    29
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Thanks for ur reply. now i changed my coding as below.

    But it' not working.when when i type 'dvd' DVD is not highlighted
    $t=$_REQUEST[txtSearch];
    	// $searchtxt=stripslashes($_REQUEST[txtSearch]);
    	echo $searchtxt=strtolower(stripslashes($_REQUEST[txtSearch]));
    	//$searchtxt1=addslashes(htmlspecialchars($searchtxt));
    	//echo $searchtxt1=addslashes(htmlspecialchars($searchtxt));
       $sql="SELECT * FROM page_content  WHERE (lower(modelno) LIKE '%$searchtxt%') or (lower(prodname) LIKE '%$searchtxt%') or (lower(proddesc) LIKE '%$searchtxt%') or (lower(prodfeature) LIKE '%$searchtxt%') or (lower(prodspec) LIKE '%$searchtxt%')";
    	$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]);
    	 $pdesc=str_replace($searchtxt,"<b><font color=red>".$searchtxt."</font></b>",$pdesc);
    	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>$pdesc<br/></p>";
    	$i=$i+1;
    	}
    PHP:
     
    balasun, Aug 4, 2008 IP