小编Vet*_*vel的帖子

使用php mysql创建嵌套的json对象

我有两个表,表1有2个字段(question_pk,question_name),表2有4个字段(ans_pk,options,question_fk和right_answer).我想像以下结构一样创建json

{
    "type": "quiz",
    "name": "Brand Colors",
    "description": "Can you identify these brands by the background color?",
    "questions": [
        {
            "name": "Can you identify this color?",
            "description": "#ea4c89",
            "answers": [
                {
                    "name": "Dribbble",
                    "description": "dribbble.png",
                    "weight": 1
                },
                {
                    "name": "Amazon",
                    "description": "amazon.png",
                    "weight": 0
                },
                {
                    "name": "Apple",
                    "description": "apple.png",
                    "weight": 0
                }
            ]
        },
        {
            "name": "Can you identify this color?",
            "description": "#3d9ae8",
            "answers": [
                {
                    "name": "Youtube",
                    "description": "youtube.png",
                    "weight": 0
                },
                {
                    "name": "Dropbox",
                    "description": …
Run Code Online (Sandbox Code Playgroud)

php mysql json recursive-query

9
推荐指数
2
解决办法
9398
查看次数

标签 统计

json ×1

mysql ×1

php ×1

recursive-query ×1