<?php 
include("../db_connection.php");
$ads_id="ads_id!=''";
$sname=$_POST['sname'];

$sql1=mysql_query("select * from tbl_maincategory where name like '%$sname%' and status='Enable'");
$num1=mysql_num_rows($sql1);
if($num1>0)
{

while($res1=mysql_fetch_assoc($sql1))
{
	$mcid=$res1['mcid'];
	
	$name=$res1['name'];
	
	?>
		  <div class="autocomplete-suggestion AdsChoose" data-index="1" id="<?php echo $mcid;?>" value="<?php echo $name;?>"><strong><?php echo strtoupper($name[0]);?></strong><?php echo substr($name, 1); ?></div>
	<?php
	
}
}


$sql2=mysql_query("select * from tbl_category where name like '%$sname%' and status='Enable' order by name asc");
$num2=mysql_num_rows($sql2);

if($num2>0)
{
while($res2=mysql_fetch_assoc($sql2))
{
	$cid=$res2['cid'];
	
	$mcid=$res2['mcid'];
	
	
	$sqlmcid=mysql_query("select * from tbl_maincategory where mcid='$mcid'");
	$resmcid=mysql_fetch_assoc($sqlmcid);
	
	$name=$res2['name'];
	
	?>
		  <div class="autocomplete-suggestion AdsChoose" data-index="1" id="<?php echo $mcid;?>" value="<?php echo $name;?>"><strong><?php echo strtoupper($name[0]);?></strong><?php echo substr($name, 1); ?> <span style="color:grey;">in category <?php echo $resmcid['name'];?></span></div>
	<?php
	
}
}
$sql3=mysql_query("select * from tbl_subcategory where name like '%$sname%' and status='Enable' order by name asc");
$num3=mysql_num_rows($sql3);
if($num3>0)
{
while($res3=mysql_fetch_assoc($sql3))
{
	$sid=$res3['sid'];
	
	$cid=$res3['cid'];
	
	$mcid=$res3['mcid'];
	
	$name=$res3['name'];
	
	
	$sqlmcid=mysql_query("select * from tbl_maincategory where mcid='$mcid'");
	$resmcid=mysql_fetch_assoc($sqlmcid);
	
	
	$sqlcid=mysql_query("select * from tbl_category where cid='$cid'");
	$rescid=mysql_fetch_assoc($sqlcid);
	
	
	?>
		  <div class="autocomplete-suggestion AdsChoose" data-index="1" id="<?php echo $mcid;?>" value="<?php echo $name;?>"><strong><?php echo strtoupper($name[0]);?></strong><?php echo substr($name, 1); ?> <span style="color:grey;">in category <?php echo $resmcid['name'];?></span></div>
	<?php
}
}


$sql=mysql_query("select * from tbl_ads where title like '%$sname%' and admin_status='Approved'");
if(mysql_num_rows($sql)>0)
{
while($res=mysql_fetch_assoc($sql))
{
	$ads_id=$res['ads_id'];
	
	$title=$res['title'];
	
	?>
		  <div class="autocomplete-suggestion AdsChoose" data-index="1"  value="<?php echo $title;?>"><strong><?php echo strtoupper($title[0]);?></strong><?php echo substr($title, 1); ?></div>
	<?php
	
}

}
?>

<script>
$(".AdsChoose").click(function(){

$("#search_ads").val($(this).attr('value'));


 
 
 
 if(typeof ($(this).attr('id')) != 'undefined')
 {
	  
	  $("#Mcid").val($(this).attr('id'));
	 
 }
 $("#productsearch").css('display','none');
 

 
});
</script>