来自数据库phpmyadmin的动态下拉菜单



我正试图从数据库中显示我的网站菜单,但我不知道如何进行下拉操作。如果我保持原样,我的首页将充满数据库中多次显示的页面。有什么想法吗?

我更改了很多次代码,不知道该怎么办了。

这就是我的页面数据库的样子:

CREATE TABLE `pagini` 
(
`Id` int(11) NOT NULL,
`nume_meniu` varchar(255) DEFAULT NULL,
`pagina` varchar(255) DEFAULT NULL,
`Meniu` int(1) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
INSERT INTO `pagini` (`Id`, `nume_meniu`, `pagina`, `Meniu`) 
VALUES (1, 'Dashboard', 'Admin.php', 1),
(2, 'Adaugare Produse', 'Adauga_Produse.html', 1),
(3, 'Stergere Produse', 'Sterge_Produse.html', 1),
(4, 'Vizualizare produse', 'editare_chirurgie.php', 1),
(5, 'Vizualizare produse', 'editare_aparatura.php', 0),
(6, 'Vizualizare produse', 'editare_cardio.php', 0),
(7, 'Vizualizare produse', 'editare_cons.php', 0),
(12, 'Vizualizare mesaje', 'Viz_Contact.php', ),
(13, 'Statistici', 'Statistici.html', 0),

PHP代码:

<?php
require_once("connection.php");
$page = basename($_SERVER['PHP_SELF']);
$IdUser = $_SESSION["user_id"];
$query = "SELECT pagini.Meniu, pagini.nume_meniu, pagini.pagina 
FROM pagini INNER JOIN drepturi ON drepturi.IdPage=pagini.Id 
WHERE drepturi.IdUser='$IdUser'";
$sql1 = mysqli_query($db, $query);
$rows = mysqli_num_rows($sql1);
if ($rows > 0) {
echo "<ul>";
$sw = 0;
while ($myrow = mysqli_fetch_array($sql1, MYSQLI_ASSOC)) {
if ($myrow["pagina"] == $page) {
$sw = 1;
}
if ($myrow["Meniu"] == 1) {
// echo "<li><a href='".$myrow["pagina"]."'>".$myrow["nume_meniu"]."</a></li>";
echo "
<div class="top-bar" id="meniu-mare">
<div class="top-bar-left">
<ul class="dropdown menu" data-dropdown-menu>
<li class="menu-text">
<img src="1.png">
</li>
<li><a id="categorii" href='" . $myrow["pagina"] . "'>" . $myrow["nume_meniu"] . "</a></li>";
} else {
echo "
<li class="has-submenu">
<a id="categorii">
PRODUSE
</a>
<ul id="sub-categorii" class="submenu menu vertical" data-submenu>
<li><a id="categorii" href='" . $myrow["pagina"] ."'>" . $myrow["nume_meniu"] . "</a></li>                    
<li><a id="categorii" href='" . $myrow["pagina"] . "'>" . $myrow["nume_meniu"] . "</a></li>
</ul>
</li>

将查询更改为

$query = "SELECT pagini.Meniu, pagini.nume_meniu, pagini.pagina 
FROM pagini INNER JOIN drepturi ON drepturi.IdPage=pagini.Id 
WHERE drepturi.IdUser='$IdUser' group by pagini.nume_meniu order by pagini.nume_meniu asc";

相关内容

  • 没有找到相关文章