<?php
require_once 'config.php';
function arraymerger($c,$c1)
	{
	    $arr=array();
	    $i=0;$k=0;$l=0;
	    for($j=0;$j<count($c1);$j++)
	    {
              $arr[$k]=$c[$i];
              $k++;$i++;
              if($i==count($c)){
                  $i=0;
                  $l=1;
              }
               $arr[$k]=$c[$i];
              $k++;$i++;
              if($i==count($c)){
                  $i=0;
                  $l=1;
              }
              $arr[$k]=$c1[$j];
              $k++;
	    }
	if ($l==0){
	    for(;$i<count($c);$i++){
	        $arr[$k]=$c[$i];
	        $k++;
	    }
	}
	return $arr;
	}
//$error=false;
$errors=array();
$cities=array();
$cities1=array();
$smsflag=1;
if(isset($_GET['smsflag'])){
$smsflag=$_GET['smsflag'];}
$query='SELECT * FROM banners ';

$row = mysqli_query($con,$query);
     
    if (mysqli_num_rows($row) >= 1) {
		//$r=mysqli_fetch_array($row)	;
			
		 while($r=mysqli_fetch_array($row)){
			 
			$cities[]=['id'=>$r['id'],'type'=>'banners','image'=>$r['image'],'url'=>$r['url']];
			
			// $cities['images']=$images;
			
			
		}   
		//$errors['banners']=$cities;
		
    } else {
        
		
    }
	if ($smsflag==1){
	$query1='SELECT * FROM smsbanners ';

$row1 = mysqli_query($con,$query1);
     
    if (mysqli_num_rows($row1) >= 1) {
		//$r=mysqli_fetch_array($row)	;
			
		 while($r1=mysqli_fetch_array($row1)){
			 
			$cities1[]=['id'=>$r1['id'],'type'=>'smsbanners','image'=>$r1['image'],'url'=>$r1['url']];
			
			// $cities['images']=$images;
			
			
		}   } }
		//$errors['smsbanners']=$cities1;
		//$errors['product_images']=$images;
		
		if ($smsflag==1){
			$city=arraymerger($cities,$cities1); }  else { $city=$cities;}
	$city1=$city;
	//	shuffle($city1);
		
		if ((count($city)==0)){
        
		$errors['success']='There is no banners found';
    } else {
		$errors['success']='Instagram banners data';
	//	shuffle($city1);
		$errors['allbanners']=$city1;   
	}
	 
	echo json_encode($errors);
	
?>