我有一个带有以下正文的index.php文件:
<body>
<!-- include navigation -->
<header>
<?php include 'navi.php'; ?>
</header>
<!-- include content -->
<section>
<div>
<?php
if (!empty($_GET['page'])) {
if (!file_exists($_GET['page'] . ".php")) {
include("home.php");
} else {
include($_GET['page'] . ".php");
}
} else {
include("home.php");
}
?>
</div>
</section>
<!-- include footer -->
<?php include 'footer.html'; ?>
</body>
和nav.php:
<nav>
<ul>
<li>
<img onclick="window.location.href = '?page=home'" id="logo" src="./images/logo.png">
</li>
<li>
<a href="?page=search">Search Events</a>
</li>
<li>
<a href="?page=create">Create Event</a>
</li>
<li>
<a href="?page=account">My Account</a>
</li>
<li>
<a href="logout.php" >
<img id="logout" src="./images/logout.png">
</a>
</li>
</ul>
</nav>
在搜索页面中,我有一个简单的表格来搜索数据库中的特定名称和类型。如何在搜索文件中回显我的结果?如果我只是include './search.php';
,则会丢失index.php中的所有代码,不幸的是我不能包含这样的内容:include 'index.php?page=search';
答案 0 :(得分:0)
而不是include "index.php?page=search"
,您可以header("location:index.php?page=search")
,然后在index.php文件include $_GET['page'].'php'
中。当然,您应首先验证$_GET['page']
实际上是一个集变量。