<?php
$dt=section();
echo json_encode($dt);

function section(){
  global $ar,$db;
  $dt=array();


  $sql="SELECT a.section_id,count(*) as jum,b.title,a.site_id,c.title as site,c.icon_url from gnews_item a JOIN gnews_section b ON a.section_id=b.id JOIN gnews as c ON a.site_id=c.id where a.st_body=2 and a.st>0  and a.title!='' and char_length(a.img)>40 group by section_id order by b.title";
  //$dt['sql'][1]=$sql;
  $res=mysqli_query($db,$sql);
  if(mysqli_num_rows($res)>0){
    $dt['success']=true;
    $dt['get_at']=date("Y-m-d H:i:s");
    $dt['count']=mysqli_num_rows($res); 
    $a=0;
    while($r=mysqli_fetch_assoc($res)) {
      $dt['data'][$a]['id']=$r['section_id'];
      $dt['data'][$a]['title']=ucwords(strtolower($r['title']));
      $dt['data'][$a]['count']=$r['jum'];
      $dt['data'][$a]['site_id']=$r['site_id'];
      $dt['data'][$a]['site']=$r['site'];
      $dt['data'][$a]['icon']=$r['icon_url'];
      $dt['data'][$a]['select']=0;
      $a++;
    }
  } else {
    $dt['error']=true;
    $dt['message']="Data not found";        
  }
  return $dt;
  $db->close();
}
?>
/home/u1731472/public_html/
sub/cpapp_ekbis/api/v2/php/sections.php