好的,我尝试了几天,但我做不到,所以我首先尝试一步一步来我需要正确地从数据库中获取信息并以表格形式显示这里是数据库
CategoryID | CategoryName | ParentID
----------------------------------------
1 | FirstMenuCat1 | 0
2 | FirstMenuCat2 | 0
3 | SubMenuCat1 | 1
4 | SubMenuCat2 | 1
5 | SubMenuCat3 | 2
这是我最后一次成功的尝试,所以我知道我从数据库中获取了正确的数据,但我不知道如何使它成为一个表单:
<?php
require_once ('mysqli_connect.php');
$q = "SELECT CategoryName FROM menus where ParentID = '0' ORDER by CategoryID";
$r = @mysqli_query ($dbc, $q) or die("Error: ".mysqli_error($dbc));
/* associative array */
while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC)){
printf ("%s\n", $row["CategoryName"]);
}
?>
这是我的尝试,但它不起作用
/* associative array */
while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC)){
foreach($row){
echo "<option value=\"". urlencode( $_ ) ."\" $selected >$_</option>\n";
$selected = ""; // only the first element will be marked as selected
}
}
?>
有任何想法吗?