使用PHP将JSON结果返回为1对多关系Mysql查询 单词表(单词id、单词、含义) 同义词(s_id,同义词,单词_id) 反义词(a_id,antonym,word_id)
我有三张桌子<代码>单词表包含单词和含义<代码>同义词表包含同义词对应的单词表,使用单词id作为外键。使用PHP将JSON结果返回为1对多关系Mysql查询 单词表(单词id、单词、含义) 同义词(s_id,同义词,单词_id) 反义词(a_id,antonym,word_id),php,mysql,json,Php,Mysql,Json,我有三张桌子单词表包含单词和含义同义词表包含同义词对应的单词表,使用单词id作为外键。 反义词表包含反义词对应的单词表,使用单词id作为外键 我希望通过PHP Mysql结果获得JSON结果,如下所示 words [{ "word":"defy", "meaning":"challenge", "synonyms":[ "violate", "withstand", "ignore" ], "antonyms":[ "respect", "abet", "like" ] }, "
反义词
表包含反义词对应的单词表,使用单词id作为外键
我希望通过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
是您的查询结果。尝试以下操作:
$json_result = json_encode($result);
这是假设
$result
是您的查询结果。粘贴您的代码。您是否有代码要共享或希望有人为您编写所有代码?关于json\u encode
?粘贴您的代码。您是否有代码要共享或希望有人为您编写所有代码?关于json\u encode
?