我在 MySql 中有 2 个表
部分
ID Name
=====================
1 Section1
2 Section2
类别
ID SectionID Name
=========================================
1 1 Category1
2 1 Category2
3 2 Category3
这就是我现在所拥有的:
$sql_section = "select * from section";<br>
$sql_category = "select * from category";<br>
$result_section = mysql_query($sql_section) or die("Could not execute query.");
$result_category = mysql_query($sql_category) or die("Could not execute query.");
echo json_encode(???????);
我想在 PHP 中编码 JSON 以获得如下所示的结果:
{sections:[
{sectionName: "Section1", categoryList: [{categoryName: "category1"},
{categoryName: "category2"}]},
{sectionName: "Section1", categoryList: [{categoryName: "category3"}]}<br>
]}
关于如何设计一个看起来像这样的数组的任何线索?