到目前为止,我有以下代码:
$dbc = mysql_connect($db_host,$db_user,$db_pass);
$sdb = mysql_select_db($db_database);
$query = 'SELECT category_name, subcategory_name FROM categories, subcategories WHERE subcategory_parent = category_name ORDER BY category_name ASC, subcategory_name ASC';
$result = mysql_query($query, $dbc)
or die (mysql_error($dbc));
$row = mysql_fetch_array($result);
$catname = $row["category_name"];
$subcatname = $row["subcategory_name"];
$last = $catname;
$last2 = $subcatname;
$query2 = "SELECT subsubcategory_name FROM subsubcategories WHERE subsubcategory_parent = '$subcatname' ORDER BY subsubcategory_name ASC";
$result2 = mysql_query($query2, $dbc)
or die (mysql_error($dbc));
$row2 = mysql_fetch_array($result2);
$subsubcatname = $row2["subsubcategory_name"];
当我回显$ subsubcatname变量时,这不起作用,所以我假设我对如何做到这一点的想法是完全错误的。也许它应该通过加入表来实现?