1

I am like to view the data retrieved by the SQL statement but when doing it only json_response display the data but what I want to see is echo json_encode($json_response) format of data.
I follow this tutorial but did not get the same result.
json_encode($json_response) shows no data AKA plain screen
http://www.webslesson.info/2016/05/convert-data-from-mysql-to-json-formate-using-php.html

$query = "SELECT * from LibraryEvents";

  $result = mysqli_query($connDB,$query);

  $json_response = array();
  while($row = mysqli_fetch_assoc($result)) {
        $json_response[] = $row;
        //array_push($json_response,$row_array);
  }

  echo '<pre>';
  print_r($json_response);
  echo '<pre>';
  echo json_encode($json_response);
7
  • So, what's the output you see? Commented Jan 28, 2018 at 17:10
  • print_r($json_response) show all data but echo json_encode($json_response) show no data Commented Jan 28, 2018 at 17:13
  • do you have any data inserted in LibraryEvents table ? Commented Jan 28, 2018 at 17:16
  • There is data since I did say print_r display data but json_encode does not display anything Commented Jan 28, 2018 at 17:17
  • $connDB = mysqli_connect("localhost","user","pass","database"); its your $connDB is right ? Commented Jan 28, 2018 at 17:28

1 Answer 1

1

Frequenty, this is due to your response having accents: if your response has accents (é, à, etc.), json_encode will not work properly.

This might help you: How to json_encode array with french accents?

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks. Your answer solve the problem. After changing word with accent, it solved everything.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.