我在MySQL的2個表如何設計一個數組結構並使用PHP編碼爲Json?
科
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(???????);
而且我想編碼JSON在PHP中得到看起來像這樣的結果:
{sections:[
{sectionName: "Section1", categoryList: [{categoryName: "category1"},
{categoryName: "category2"}]},
{sectionName: "Section1", categoryList: [{categoryName: "category3"}]}<br>
]}
的我如何設計一個數組,看起來像這樣的任何線索?
請不要使用過時的mysql_XXX功能,使用庫MySQLi或PDO。 – Barmar 2012-08-16 07:30:54
爲什麼?任何建議的文章閱讀? – Vicheanak 2012-08-16 11:54:43
讀http://stackoverflow.com/questions/548986/mysql-vs-mysqli-in-php – Barmar 2012-08-16 15:00:26