我想在dashboard-home.php中显示数据库中的总记录。
我收到未定义索引的错误
如何正确链接到页面以获取同一页面中的内容我指的是同一div中的不同页面。
<!DOCTYPE html>
<html>
<head>
<title>SIS Dashboard</title>
<link rel="stylesheet" type="text/css" href="../css/bootstrap/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="../css/main.css">
</head>
<body id="dashbody">
<div class="row dashboard-head">
<div class="container">
<div class="col-md-2">
<a href="dashboard.php?dash-home"><h2>DASHBOARD</h2></a>
</div>
<div class="tpad navbar-right">
<div class="col-md-8">
<p><b><?php echo "Welcome " .$_SESSION['user']; ?></b></p>
</div>
<div class="col-md-4 logout-a">
<a href="logout.php?logout" class="btn btn-info btn-sm">Logout</a>
</div>
</div>
<div class="row db-wrapper">
<div class="col-md-3 left-panel">
<ul>
<li><a href="dashboard.php?page=user">User Panel</a></li>
- <a href="dashboard.php?page=view_users">View Users</a><hr>
<li><a href="dashboard.php?page=gallery">Gallery Panel</a></li>
- <a href="dashboard.php?page=view_gallery">View Gallery</a><hr>
<li><a href="dashboard.php?news">News Panel</a></li>
- <a href="dashboard.php?view_news">View All News</a><hr>
<li><a href="dashboard.php?page=events">Events Panel</a></li>
- <a href="dashboard.php?page=view_events">View Events</a>
</ul>
</div>
<div class="col-md-9 right-panel">
<?php
if($_GET['dash-home']){
include'dashboard-home.php';
}
if(isset($_GET['gallery'])){
include'pages/gallery_panel.php';
}
if(isset($_GET['news'])){
include'news_panel.php';
}
if(isset($_GET['view_news'])){
include'view_news.php';
}
if(isset($_GET['edit_news'])){
include'edit_news.php';
}
?>
</div>
</div>
</div>
</div>
</body>
</html>
答案 0 :(得分:0)
请注意,您的网址为 dashboard.php ,没有dashboard.php?dash-home=1
的查询字符串,这意味着此条件不起作用,您将获得未定义的索引通知你得到了:
if($_GET['dash-home']){
如果您检查代码,则表示您已使用isset()
进行其他输入,因此您还需要在此处添加isset()
:
if(isset($_GET['dash-home'])){
根据您的信息中心链接:
<a href="dashboard.php?dash-home"><h2>DASHBOARD</h2></a>
您无法从dash-home
获取值,因为您没有使用dash-home
的值,您可以使用:
<a href="dashboard.php?dash-home=1"><h2>DASHBOARD</h2></a>
还有一点,$_SESSION
在顶层需要session_start()
,而我在您的文件中找不到此功能。这只是旁注,你需要注意这一点。
<强>更新强> 如果要显示默认包含的文件而不是需要使用其他部分,根据您的注释,您需要根据条件使用一个包含文件,请尝试:
<?php
if(isset($_GET['dash-home'])){
include 'dashboard-home.php';
}
elseif(isset($_GET['gallery'])){
include 'pages/gallery_panel.php';
}
elseif(isset($_GET['news'])){
include 'news_panel.php';
}
elseif(isset($_GET['view_news'])){
include 'view_news.php';
}
elseif(isset($_GET['edit_news'])){
include 'edit_news.php';
}
else{
include 'dashboard-home.php';
}
?>
答案 1 :(得分:0)
我建议使用switch而不是if-else
您正在查看$ _GET [&#39; dash-home&#39;]但您需要查看$ _GET [&#39;页面&#39;]
尝试:
if(isset($_GET['page']))
{
switch ($_GET['page'])
{
case 'dash-home':
include 'dashboard-home.php';
break;
case 'gallery':
include 'pages/gallery_panel.php';
break;
and so on.....
}
}