繁体   English   中英

使用PHP将JSON结果作为1返回到许多关系Mysql查询

[英]Return JSON Result as 1 to many Relationship Mysql query using PHP

  1. word_table(word_id,单词,含义)
  2. 同义词(s_id,同义词,word_id)
  3. 反义词(a_id,反义词,word_id)

我有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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM