0

hi i wanted to make my database table look a bit smoother and better looking by making it a json array and this is my code :

<?php
include 'conn.php';

$getpost="SELECT * FROM posts;";

$post=$conn->query($getpost);

$postarray= array();

while($row = mysqli_fetch_array($post, MYSQL_ASSOC){

    $temp['id'] = $row['id'];
    $temp['postcont'] = $row['postcont'];
    $temp['writer'] = $row['writer'];
    $temp['posttime'] = $row['posttime'];

    array_push($postarray, $temp);

}

echo json_encode(array("posts"=>$postarray),JSON_UNESCAPED_UNICODE);
?>

but i faced an error

Notice: Use of undefined constant MYSQL_ASSOC - assumed 'MYSQL_ASSOC' on line 10

Warning: mysqli_fetch_array() expects parameter 2 to be integer, string given on line 10 {"posts":[]} and thanks for the help ^_^

  • Missing a parenthesis to close the while-condition – Qirel Jul 30 '17 at 09:40
  • :o you are right thank but another error appeared **Notice: Use of undefined constant MYSQL_ASSOC - assumed 'MYSQL_ASSOC' in /storage/ssd2/168/2173168/public_html/getposts.php on line 10 Warning: mysqli_fetch_array() expects parameter 2 to be integer, string given in /storage/ssd2/168/2173168/public_html/getposts.php on line 10 {"posts":[]}** @Qirel – abid mohamed Jul 30 '17 at 09:42
  • it's `MYSQLI_ASSOC` - missing an `I` there – Jeff Jul 30 '17 at 09:49
  • Thanks you saved my day :D @Jeff – abid mohamed Jul 30 '17 at 09:53

0 Answers0