<?php

// Created by Ibrohimjon Ahmadjonov Ilhomjon o'g'li on 10.02.2020
header('Content-type: text/html; charset=UTF-8');
require "connect.php";

 
$umum_soni = 0;  
   
$count=1;

$sql_sorov = "SELECT Id,user_id,sorov_turi,sorov_izox,time FROM savollar WHERE yuklandi = 0";

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

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

		$sorov_id=$row['Id']; 
		$user_id=$row['user_id']; 
		$sorov_turi=$row['sorov_turi']; 
		$sorov_izox=$row['sorov_izox']; 
		$time=$row['time']; 
		$sorov_izox = str_replace('"', '`', $sorov_izox); 
        $myDateTime = DateTime::createFromFormat('Y-m-d H:i:s', $time);
        $newDateString = $myDateTime->format('H:i:s d.m.Y');
        
			$mysql_qry = "UPDATE savollar SET yuklandi=1 WHERE Id = '".$sorov_id."'";
			if($conn->query($mysql_qry) == TRUE){ 
			     echo nl2br("".$sorov_id."|".$user_id."|".$sorov_turi."|".$sorov_izox."|".$newDateString."\n");   
			     $count++;
			} 
    }
    if($count>0){
        $conn->close();
		return;
    }
}
echo 'no';
$conn->close();
?>