return multiple rows from mysqli php and encode json

Solutions on MaxInterview for return multiple rows from mysqli php and encode json by the best coders in the world

showing results for - "return multiple rows from mysqli php and encode json"
Silvia
07 Sep 2019
1<?php
2    $dashboard_content_token = $_REQUEST["dashboard_content_token"];
3    $token = "g4";
4
5    require(cc_scripts/connect.php);
6
7    $sql = "SELECT * FROM `dashboard_content`";
8    $check = strcmp("$token", "$dashboard_content_token");
9    $statement = mysqli_query($con, $sql);
10    if (check) {
11        $rows = mysqli_fetch_assoc($statement);
12        if (!$rows) {
13            echo "No results!";
14        } else {
15
16          do {
17             $news_id = $rows['news_id'];
18             $image_url = $rows['image_url'];
19             $news_title = $rows['news_title'];
20             $news_description = $rows['news_description'];
21             $news_article = $rows['news_article'];
22
23               $result['dashboard content: '][] = array('news_id' => $news_id, 'image_url' => $image_url, 'news_title' => $news_title, 'news_description' => $news_description, 'news_article' => $news_article); 
24
25
26          } while ($rows = mysqli_fetch_assoc($statement));
27
28        mysqli_free_result($statement);
29        echo json_encode($result);
30    }
31}
32?>
33