[英]Return JSON Result as 1 to many Relationship Mysql query using PHP
我有3张桌子。 word_table
包含单词和含义。 synonyms
表包含使用word_id作为外键的对应于word_table的同义词。 antonyms
表包含使用word_id作为外键的反义词word_table
我想通过PHP Mysql结果获取JSON结果,如下所示
words
[{
"word":"defy",
"meaning":"challenge",
"synonyms":[ "violate", "withstand", "ignore" ],
"antonyms":[ "respect", "abet", "like" ]
},
"word":"defy",
"meaning":"challenge",
"synonyms":[ "violate", "withstand", "ignore" ],
"antonyms":[ "respect", "abet", "like" ]
},
"word":"defy",
"meaning":"challenge",
"synonyms":[ "violate", "withstand", "ignore" ],
"antonyms":[ "respect", "abet", "like" ]
}
]
尝试这个:
$json_result = json_encode($result);
假设$result
是查询的结果。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.