1

I retrieved REST API from MySQL but look appears disgusting in Postman and uncomfortable for the following use.

enter image description here

I just begin to study PHP and can to a little bit.

My code:

<?php   
$connect = mysqli_connect("localhost", "***", "***", "***");

$sql = "SELECT `id_question`, `question`, `opt_asnwer_1`, `opt_asnwer_2`, `opt_asnwer_3`, `opt_asnwer_4`, `right_answer` FROM `questions`";
$result = mysqli_query($connect, $sql);
$json_array = array();

while($row = mysqli_fetch_assoc($result))
    {
        $json_array[] = $row;
    }
echo json_encode($json_array);

?>  

What look which I want to make. Example:

enter image description here

Please help me.

Yevgen
  • 93
  • 1
  • 1
  • 8
  • 1
    try sending json header `header('Content-Type: application/json');` before `json_encode` – Ghostff Apr 08 '19 at 21:54
  • 1
    https://stackoverflow.com/questions/7381900/php-decoding-and-encoding-json-with-unicode-characters – Don't Panic Apr 08 '19 at 21:54
  • Very simple. Thanks! – Yevgen Apr 08 '19 at 22:13
  • 1
    Note: The object-oriented interface to `mysqli` is significantly less verbose, making code easier to read and audit, and is not easily confused with the obsolete `mysql_query` interface. Before you get too invested in the procedural style it’s worth switching over. Example: `$db = new mysqli(…)` and `$db->prepare("…")` The procedural interface is an artifact from the PHP 4 era when `mysqli` API was introduced and ideally should not be used in new code. – tadman Apr 08 '19 at 22:51
  • you could simply use `echo` like this `echo '
    ';
       print_r($your_variable);
       echo '
    ';` this will print the pretty way you want
    – Andrei Fiordean Apr 10 '19 at 09:24

0 Answers0