Location: PHPKode > projects > News Manager - RSS aggregator > newsmanager/quicksearch_qry.php
<?php
	/*******************************************************************************
     **  File          :  quicksearch_qry.php                                     **
     **  Author        :  G.Ramkumar                                              **
     **  Description   :  Quick search query									  **
  	 **  Date          :  14/07/2005                                              **
     **  Last Modified :  02/08/2005                                              **
     **  PHP Version   :  5.0.3                                                   **
     **                                                                           **
     *******************************************************************************/
$text=strtoupper(trim(stripslashes($_REQUEST['search'])));
$text=str_replace("'","||",$text);

$totalitems="select * from rssurl_newsitem where language='".$_REQUEST['lang']."'";
$totalitem_res=$pg_sql->query_pass($totalitems,"4");

$totalitems_new="select * from new_newsitem where language='".$_REQUEST['lang']."'";
$totalitem_new_res=$pg_sql->query_pass($totalitems_new,"4");

$total_item=count($totalitem_res)+count($totalitem_new_res);
if($total_item>0)
{
	$Totalsearch_qry="select * from rssurl_newsitem where frontend_export='Y' and language='$lang' and  (upper(news_title) like '%$text%' or upper(description) like '%$text%')";
	$Total_res=$pg_sql->query_pass($Totalsearch_qry,"4");
	$total_num = count($Total_res);

	$Totalsearch_qry_new="select * from new_newsitem where language='$lang' and (upper(title) like '%$text%' or upper(body) like '%$text%')";
	$Total_res_new=$pg_sql->query_pass($Totalsearch_qry_new,"4");
	$total_num_new = count($Total_res_new);


	$limit = 10; // Set limit display news item per page
	$offset = 0;

	if($_REQUEST['offset']>0)
	 {
		   $offset = $_REQUEST['offset'];
	 }

	//echo $total_num."==>>".$total_num_new;

 	$search_qry="select * from rssurl_newsitem  where frontend_export='Y' and language='$lang' and (upper(news_title) like '%$text%' or  upper(description) like '%$text%') limit $limit offset $offset";
	$search_res=$pg_sql->query_pass($search_qry,"4");


	$search_qry_new="select * from new_newsitem where language='$lang' and (upper(title) like '%$text%' or upper(body) like '%$text%') limit $limit offset $offset";
	$search_res_new=$pg_sql->query_pass($search_qry_new,"4");
}
$cnt=count($search_res);
$cnt_new=count($search_res_new);


for($xm=0;$xm<$cnt;$xm++)
{
$xml_id_ .=$search_res[$xm]['url_newsitem_id'].",";
}
for($xm_=0;$xm_<$cnt_new;$xm_++)
{
$xml_id_new .=$search_res_new[$xm_]['newsitem_id'].",";
}

//$execute = microtime();
//$time="(".(number_format($execute,2))." seconds).";

?>

 <table width="95%" border="0" cellspacing="0" cellpadding="0" align="center">

<?
if($cnt >0 || $cnt_new>0)
{
?>
 <tr>
    <td class="heading5" height="25" colspan="2"><?=$search_results_?></td>
	 <td align="right" width="5%" colspan="2" class="heading5" valign="middle">
	    <a target="_new" href="xml.php?id=<?=base64_encode(trim($xml_id_,","))?>&new_id=<?=base64_encode(trim($xml_id_new,","))?>"><?if($display_style_==1){?><img src="images/rss-2.0.jpg" width="80" height="15" border="0" alt="Link to RSS Feed"><?}else{?> <img src="images/<?=$rss_style_?>"  border="0" align="absmiddle" alt="Link to RSS Feed"><?}?></a>
     </td>
 </tr>
<tr>
  <td valign="middle" width="40%" height="25" colspan="4" class="headingsmall"><?=1+$offset?>&nbsp;<?=$search_foundto__?>&nbsp;<?=$cnt+$offset+$cnt_new?>&nbsp;<?=$search_foundres__?>&nbsp; <?=$total_num+$total_num_new?>&nbsp;<?=$search_foundwith__?>&nbsp;<?=$total_item?>&nbsp;<?=$search_foundnews__?></td>
   <!--td valign="top"  height="20"  colspan="4" class="headingsmall"><?=1+$offset?> to <?=$cnt+$offset+$cnt_new?> results of <?=$total_num+$total_num_new?> within a total of <?=$total_item?> news items</td-->
 </tr>

<?
}
else{
?>
<tr><td class="heading5" height="25" colspan="2"><?=$search_results_?></td></tr>
 <tr>
   <td  valign="middle" class="cont" height="200" colspan="4" align="center"><?=$noresults__?>'<font class="msg"><?=ucfirst(strtolower($text))?></font>'<br></td>
 </tr>
 <tr><td>&nbsp;</td></tr>

<?
}
for($i=0;$i<$cnt;$i++)
{
    $id=$search_res[$i]['url_newsitem_id'];
    $ch_id=$search_res[$i]['rss_channel_id'];
    $desc=html_entity_decode(strip_tags($search_res[$i]['description']));
    $desc=substr($desc,0,$search_length__);
    $url_=$search_res[$i]['url'];

    $hour=str_replace(":","h",$search_res[$i]['hour']);
	$date=explode("-",$search_res[$i]['pubdate']);
	$date=$date[2]."/".$date[1]."/".$date[0];

    $yesterday = strftime ("%e/%m/%Y", strtotime("-1 day"));
	$yday=explode("/",$yesterday);
			/*
	        if(substr($yday[1],0,1)==0)
	          $yday[1]=str_replace("0","",$yday[1]);
	        else
	        */
	          $yday[1]=$yday[1];

	        if(strlen(trim($yday[0]))==1)
			   $yday[0] ="0".trim($yday[0]);


	  $yesterday=trim($yday[0])."/".$yday[1]."/".$yday[2];
	  $today=date('d/m/Y');

	  		if($date==$today)
			  $pubdate=$today_;
			elseif($date == $yesterday)
			  $pubdate=$yesterday_;
			else
			 $pubdate=$date;

       $cate_query="select * from newsitem_category where newsitem_id=$id";
       $catitem_res=$pg_sql->query_pass($cate_query,"4");
                     for($y=0;$y<count($catitem_res);$y++)
                     {
					     if($catitem_res[$y][category_id]!="") //*** Getting category name
						  {
							 $cat_id=$catitem_res[$y][category_id];
							 $cat_nameqry="select * from category where category_id=$cat_id";
							 $cat_nameres=$pg_sql->query_pass($cat_nameqry,"4");
							 $category_name .=$cat_nameres[0]['category_name']."/";
						  }


					  }

					  $categoryname=rtrim($category_name,"/");

					  unset($category_name);
//Repalced Title

		$title=str_replace("||","'",$search_res[$i]['news_title']);
		$rep_title=$title;
		$rep_title=str_replace("é","é",$rep_title);
		$rep_title=str_replace("’","’",$rep_title);
		$rep_title=str_replace("è","è",$rep_title);
		$rep_title=str_replace("Ã","à",$rep_title);
		$rep_title=str_replace("àª","ê",$rep_title);
		$rep_title=str_replace("‘","‘",$rep_title);
		$rep_title=str_replace("à»",û,$rep_title);
		$title=$rep_title;

//*** Desc
        $rep_desc=$desc;
		$rep_desc=str_replace("é","é",$rep_desc);
		$rep_desc=str_replace("’","’",$rep_desc);
		$rep_desc=str_replace("è","è",$rep_desc);
		$rep_desc=str_replace("Ã","à",$rep_desc);
		$rep_desc=str_replace("àª","ê",$rep_desc);
		$rep_desc=str_replace("‘","‘",$rep_desc);
		$rep_desc=str_replace("à»",û,$rep_desc);
    	$desc=$rep_desc;


		$channel_image=$search_res[$i]['image'];
		$dir="login/newsimages/";
		if (is_dir($dir))
		{
		 if ($dh = opendir($dir))
		 {
		   while (($file = readdir($dh)) !== false)
		   {
		 	if(($file != ".") && ($file != ".."))
			{
				$img=explode(".",$file);
				if($img[0]==$ch_id)
				{
				  $path=pathinfo($file);
				  $name=$path['extension'];
				  if($name == "jpg" || $name =="gif" )
					$image_pre='<a href="<?=$url_?>" target="_new"><img src="login/newsimages/'.$file.'" border="0" width="'.$width_.'" height="'.$height__.'"></a>&nbsp;';

				}

			}
	  	  }
		   closedir($dh);
	     }
	  }

		if(strstr($channel_image,"http://"))
		  $channel_image='<a href="<?=$url_?>" target="_new"><img border="0" height="60" width="80" src="'.$channel_image.'"></a>&nbsp;';
		else
		  $channel_image=$image_pre;

?>
<tr>
  <td valign="top" class="cont1" colspan="4"><a href="<?=$url_?>" target="_new" class="contblue"><?=$title?></a></td>
 </tr>
 <tr><td class="cont1" valign="top" colspan="3"><?=str_replace("||","'",$desc).'....'?><br>
  <font class="contgrey"><?=$pubdate." ".$hour?></font>
  <?if($categoryname!="")
 //     echo "-<font class='contgrey'>".$categoryname."</font>";

  ?>

  </td>
  <?if($search_res[$i]['image']!=""){?>
   <td valign="middle" align="center" width="5%" colspan="1"><?=$channel_image?></td>
  <?}?>
</tr>

<tr><td colspan="4" height='7'></td></tr>
<?
unset($categoryname);
}

for($j=0;$j<$cnt_new;$j++)
{
    $id_new=$search_res_new[$j]['newsitem_id'];
    $desc_new=strip_tags($search_res_new[$j]['introtext']);
    $desc_new=substr($desc_new,0,$search_length__);
    $hour_new=str_replace(":","h",$search_res_new[$j]['hour']);
	$date=explode("-",$search_res_new[$j]['pubdate']);
	$date=$date[2]."/".$date[1]."/".$date[0];

    $yesterday = strftime ("%e/%m/%Y", strtotime("-1 day"));
	$yday=explode("/",$yesterday);
	        /*
	        if(substr($yday[1],0,1)==0)
	          $yday[1]=str_replace("0","",$yday[1]);
	        else*/
	          $yday[1]=$yday[1];

	          if(strlen(trim($yday[0]))==1)
			   $yday[0] ="0".trim($yday[0]);

	$id=$id_new;
    include("fod_att.php");

	$yesterday=trim($yday[0])."/".$yday[1]."/".$yday[2];
	$today=date('d/m/Y');

	  		if($date==$today)
			  $pubdate=$today_;
			elseif($date == $yesterday)
			  $pubdate=$yesterday_;
			else
			 $pubdate=$date;

     $cate_query="select * from newsitem_category where newsitem_id=$id";
     $catitem_res=$pg_sql->query_pass($cate_query,"4");
                     for($y=0;$y<count($catitem_res);$y++)
                     {
					     if($catitem_res[$y][category_id]!="") //*** Getting category name
						  {
							 $cat_id=$catitem_res[$y][category_id];
							 $cat_nameqry="select * from category where category_id=$cat_id";
							 $cat_nameres=$pg_sql->query_pass($cat_nameqry,"4");
							 $category_name .=$cat_nameres[0]['category_name']."/";
						  }


					  }

					  $categoryname=rtrim($category_name,"/");

					  unset($categoryname);
//Repalced Title

		$title_new=str_replace("||","'",$search_res_new[$j]['title']);
		$rep_title_=$title_new;
		$rep_title_=str_replace("é","é",$rep_title_);
		$rep_title_=str_replace("’","’",$rep_title_);
		$rep_title_=str_replace("è","è",$rep_title_);
		$rep_title_=str_replace("Ã","à",$rep_title_);
		$rep_title_=str_replace("àª","ê",$rep_title_);
		$rep_title_=str_replace("‘","‘",$rep_title_);
		$rep_title_=str_replace("à»",û,$rep_title_);
		$title_new=$rep_title_;

//*** Desc
        $rep_desc_=$desc_new;
		$rep_desc_=str_replace("é","é",$rep_desc_);
		$rep_desc_=str_replace("’","’",$rep_desc_);
		$rep_desc_=str_replace("è","è",$rep_desc_);
		$rep_desc_=str_replace("Ã","à",$rep_desc_);
		$rep_desc_=str_replace("àª","ê",$rep_desc_);
		$rep_desc_=str_replace("‘","‘",$rep_desc_);
		$rep_desc_=str_replace("à»",û,$rep_desc_);
    	$desc_new=$rep_desc_;


?>
<tr>
  <td valign="top" class="cont1" colspan="4"><a href="view_fodarticle.php?id=<?=$id_new?>&lang=<?=$lang?>" class="contblue"><?=$title_new?></a></td>
 </tr>
 <tr><td class="cont1" width="90%" valign="top" colspan="3"><?=str_replace("||","'",$desc_new).'....'?><br>
  <font class="contgrey"><?=$pubdate." ".$hour_new?></font>
  <?if($categoryname!="")
     // echo "-<font class='contgrey'>".$categoryname."</font>";
  ?>
   </td>
   <?if($image!=""){?>
    	<td align="center" width="10%" colspan="1" valign="middle"><a href="view_fodarticle.php?id=<?=$id?>&lang=<?=$lang?>"><?=$image?></a></td>
  <?}  unset($image); ?>

</tr>

<tr><td colspan="4" height='7'></td></tr><?
unset($categoryname);
}
?>
</table>
Return current item: News Manager - RSS aggregator