Search
 
SCRIPT & CODE EXAMPLE
 

PHP

How to format a json response in php

$response = [];

if ($con) {
  $sql = "select * from admission_view";
  $result = mysqli_query($con, $sql);
  if ($result) {
    $x = 0;
    while ($row = mysqli_fetch_assoc($result)) {
      $response[$x]['id'] = $row['id'];
      $response[$x]['name'] = $row['name'];
      $response[$x]['isActive'] = $row['isActive'];
      $response[$x]['branch']['id'] = $row['branchId'];
      $response[$x]['branch']['name'] = $row['branch'];
      $response[$x]['customerGroup']['id'] = $row['customerGroupId'];
      $response[$x]['customerGroup']['name'] = $row['customerGroup'];
      $response[$x]['customerGroup']['orderNo'] = $row['orderNo'];
      $x++;
    }
    echo json_encode($response, JSON_PRETTY_PRINT);
  }
} else {
  echo "Connection error";
}
Comment

PREVIOUS NEXT
Code Example
Php :: php shell command execution 
Php :: multiple middleware laravel 
Php :: php microtime to seconds 
Php :: laravel 404 
Php :: laravel old value or default 
Php :: woocommerce get post meta 
Php :: error in laravel 
Php :: cron run 1 time 
Php :: remove notices php 
Php :: php get tempfile 
Php :: laravel select default old value 
Php :: require_once php 
Php :: how to create wordpress shortcodes 
Php :: mkdir permission denied php 
Php :: Installation request for phpoffice/phpspreadsheet 1.4.0 - satisfiable by phpoffice/phpspreadsheet[1.4.0] 
Php :: laravel exists eloquent 
Php :: laravel subtract date 
Php :: add seconds to datetime php 
Php :: php date first day of month and last month 
Php :: laravel error storage permission denied 
Php :: cloudflare country 
Php :: use model from variable laravel 
Php :: how to call a helper function in blade 
Php :: php get first word of string 
Php :: php typecast to int 
Php :: wordpress translate specific text php 
Php :: how to print in php 
Php :: store emoji in php 
Php :: create new laravel 9 project 
Php :: laravel get first letter of each word 
ADD CONTENT
Topic
Content
Source link
Name
9+6 =