<?php

// Created by Ilhomjon on 06.03.2021
header('Content-type: text/html; charset=UTF-8');
require "connect.php";


$sql = "SELECT `region_id`, `kontr_id`, `kontr_nomi`, `qarzi_som`, `qarzi_val`, `max_sum`, `max_val`, `time`, latitude, longitude FROM `kontragentlar` WHERE 1";

mysqli_set_charset($conn,"utf8");
$result = mysqli_query($conn,"SET NAMES utf8");

$result = mysqli_query($conn, $sql);

$count=1;

$list_kontr = array();

if ($result !== false && $result->num_rows > 0) {
    while($row=mysqli_fetch_array($result)){

        $region_id=$row['region_id'];
        $dokon_id=$row['kontr_id'];
		$nomi=$row['kontr_nomi'];
		$qarzi_som=$row['qarzi_som'];
        $qarzi_val=$row['qarzi_val'];
		$max_val=$row['max_val'];
        $max_sum=$row['max_val'];
		$time=$row['time'];
		$latitude=$row['latitude'];
		$longitude=$row['longitude'];

		$nomi = str_replace('"', '`', $nomi);

    	array_push($list_kontr,
                array(
                        'region_id' => $region_id,
                        'kontr_id' => $dokon_id,
                        'kontr_nomi' => $nomi,
                        'qarzi_som' => $qarzi_som,
                        'qarzi_val' => $qarzi_val,
                        'max_sum' => $max_sum,
                        'max_val' => $max_val,
                        'time' => $time,
                        'latitude' => $latitude,
                        'longitude' => $longitude
                     )
                  );

		}

    }

echo json_encode($list_kontr);
$conn->close();
?>
