首页 > 解决方案 > JSON:使用 mysql 列过滤 mysql 数据 (PHP)

问题描述

{
  "data": [
    {
      "title": "Section 1",
      "section": [
        {
          "name": "Donut",
          "image": "https://thecustomizewindows.com/wp-content/uploads/2011/11/Nicest-Android-Live-Wallpapers.png"
        }

      ]
    },
    {
      "title": "Section 2",
      "section": [
        {
          "name": "Donut",
          "image": "https://thecustomizewindows.com/wp-content/uploads/2011/11/Nicest-Android-Live-Wallpapers.png"
        }
      ]
    },
    {
      "title": "Section 3",
      "section": [
        {
          "name": "Donut",
          "image": "https://thecustomizewindows.com/wp-content/uploads/2011/11/Nicest-Android-Live-Wallpapers.png"
        }

      ]
    }
  ]
}

我有这样写的PHP:function getAllVideo(){

        $stmt = $this->con->prepare("SELECT * FROM video");
        $stmt->execute();
        $stmt->bind_result($v_id,$video_image,$video_name,$category);
        $video = array();
        $action = array();
        while($stmt->fetch()){
            $temp = array();

            $temp['v_id'] = $v_id;
            $temp['video_image'] = $video_image;
            $temp['video_name'] = $video_name;
            $temp['category'] = $category;

            array_push($video, $temp);        
        }        
        return $video;
    }

你能帮我如何设计这段代码吗?我有类别列,想像这样在 Json 中排序。请协助。我正在使用 Slim-3 框架,需要 json 格式。

标签: phpmysqlarraysjsonslim-3

解决方案


推荐阅读