Advertisement
solodroid

Your Recipes App (api.php)

Oct 5th, 2017
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.29 KB | None | 0 0
  1. <?php
  2.  
  3.     include_once ('includes/variables.php');
  4.  
  5.     $connect->set_charset('utf8');
  6.    
  7.     if(isset($_GET['cat_id']))
  8.     {      
  9.             $query = "SELECT * FROM tbl_category c,tbl_recipes n WHERE c.cid = n.cat_id and c.cid = '".$_GET['cat_id']."' ORDER BY n.nid DESC";        
  10.             $resouter = mysqli_query($connect, $query);
  11.            
  12.     }
  13.     else if(isset($_GET['nid']))
  14.     {      
  15.             $id = $_GET['nid'];
  16.  
  17.             $query = "SELECT * FROM tbl_category c,tbl_recipes n WHERE c.cid = n.cat_id && n.nid = '$id'";                 
  18.             $resouter = mysqli_query($connect, $query);
  19.            
  20.     }  
  21.     else if(isset($_GET['latest_news']))
  22.     {
  23.             $limit = $_GET['latest_news'];     
  24.            
  25.             $query = "SELECT * FROM tbl_category c,tbl_recipes n WHERE c.cid=n.cat_id ORDER BY n.nid DESC LIMIT $limit";           
  26.             $resouter = mysqli_query($connect, $query);
  27.     }
  28.     else
  29.     {  
  30.             $query = "SELECT * FROM tbl_category ORDER BY cid DESC";           
  31.             $resouter = mysqli_query($connect, $query);
  32.     }
  33.      
  34.     $set = array();
  35.      
  36.     $total_records = mysqli_num_rows($resouter);
  37.     if($total_records >= 1){
  38.      
  39.       while ($link = mysqli_fetch_array($resouter, MYSQLI_ASSOC)){
  40.        
  41.         $set ['Json'][] = $link;
  42.       }
  43.     }
  44.    
  45.     header( 'Content-Type: application/json; charset=utf-8' );
  46.     echo $val= str_replace('\\/', '/', json_encode($set));  
  47.      
  48. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement