我正在尝试获得以下结构
图书
a.哈利波特
衣服
一个。衬衫
像这样从数据库中获取所有数据。我使用 php 和 iquery 做到了这一点,但我得到了以下结构 -
图书
一个。哈利波特
湾。衬衫
衣服
一个。哈利波特
湾。衬衫
所以谁能告诉我哪里出错了。我的代码是
<?php include 'dbconnect.php' ?>
<?php include 'header.php' ?>
<div id="wrapper">
<div id="content">
<div id="rightnow">
<h3 class="reallynow"></h3>
<br/>
<script src="jquery.js" type="text/javascript"></script>
<script src="jquery-ui.custom.js" type="text/javascript"></script>
<script src="jquery.cookie.js" type="text/javascript"></script>
<!-- Include the basic stylesheet: -->
<script src="jquery.dynatree.js" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
$("#tree").dynatree({
title: "Sample Theming",
// Image folder used for data.icon attribute.
imagePath: "skin-custom/",
onActivate: function (node) {
return true;
}
});
});
</script>
<?php
$x1 = array();
$x2 = array();
$sql_1 = mysqli_query($con, "SELECT * FROM jsrao_db4");
while ($row_1 = mysqli_fetch_array($sql_1)) {
array_push($x1, $row_1["cat_name"]);
}
$sql_2 = mysqli_query($con, "
SELECT * FROM jsrao_db5 WHERE pro_id = $i
");
while ($row_2 = mysqli_fetch_array($sql_2)) {
array_push($x2, $row_2["pro_name"]);
}
?>
<div id="tree">
<ul>
<?php foreach ($x1 as $p) {
echo "<li class='folder'>$p"; ?>
<ul>
<?php foreach ($x2 as $q) {
echo "<li>$q";
} ?>
</ul><?php } ?>
</ul>
</div>
</div>
</div>
</div>