@Evan 试图在 newpage.php 上回显 0 结果,我如何从 newpage.php 定义 $searchQuery ...似乎我必须将所有代码重写到 newpage.php ...那里一种方法来形成对另一个页面的操作?
<?php
session_start();
error_reporting(E_ALL);
ini_set('display_errors', '1');
include_once("db_connects.php");
$queryArray = array();
$goodQuery = true;
$search_output = "";
if(isset($_POST['searchquery']) && $_POST['searchquery'] != ""){
$searchquery = preg_replace('#[^a-z 0-9?!]#i', '', $_POST['searchquery']);
{
$sqlCommand = "(SELECT id, links, page_body, page_title AS title FROM pages WHERE MATCH (page_title,page_body) AGAINST ('$searchquery'))";
}
$query = mysql_query($sqlCommand) or die(mysql_error());
$count = mysql_num_rows($query);
if($count > 1){
$search_output .= "<hr />$count results for <strong>$searchquery</strong><hr />";
while($row = mysql_fetch_assoc($query)){
$queryArray[] = $row;
}
}
else {
$goodQuery = false;
$_SESSION['error'] = true;
header("Location: newpage.php");
}
if($goodQuery){
$_SESSION['search_output'] = $queryArray;
header("Location: newpage.php");
exit;
}
else{
echo $search_output;
}
}
?>
这是 newpage.php 上的代码,一旦它离开标题..
<?php
session_start();
if(isset($_SESSION['error'])){
$search_output = "<hr />0 results for <strong>$searchquery</strong><hr />";
} else {
foreach($_SESSION['search_output'] as $value){
$value['links'];
$value['title'];
$value['page_body'];
$title = $value['title'];
$link = $value['links'];
$body = $value['page_body'];
$search_output .= "<a href='".$link."'>".$title."</a> - $body<br>";
}
}
?>
<div>
<?php echo $search_output; ?>
</div>