<?php 

require 'db.php';

$sels = $con->query("select * from home");
while($rows = $sels->fetch_assoc())
{
        $p['id'] = $rows['id'];
		$p['title'] = $rows['title'];
	    $p['status'] = $rows['status'];
		$cat =  $con->query("select catname from category where id=".$rows['cid']."");
		if($row = $cat->fetch_assoc())
		$p['catname'] = $row['catname'];
		$scat =  $con->query("select name from subcategory where id=".$rows['sid']."");
		if($row = $scat->fetch_assoc())
		$p['subcatname'] = $row['name'];
		$p['cattime'] = $rows['cattime'];
    	if($p['cattime'] == "Default")
    	{
    	    $sel = $con->query("select start_time,end_time from setting where id='1'");
            if($row = $sel->fetch_assoc())
            {
                $p['catstarttime'] = $row['start_time'];
                $p['catstoptime'] = $row['end_time'];
            }
    	}
    	else
    	{
    	    $p['catstarttime'] = $rows['catstarttime'];
    	    $p['catstoptime'] = $rows['catstoptime'];
    	}
		$cp[] = $p;
}

echo json_encode($cp);
?>