0
@Evan試圖回聲出到newpage.php還如何從newpage.php定義$ SEARCHQUERY 0結果...好像我不得不重寫所有的代碼到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>
我不太清楚你是什麼意思...我是新來的PHP ...我會刪除else語句嗎? – arianna 2013-04-04 04:45:56
@arianna所以它更清楚我會更新我的答案。 – 2013-04-04 04:48:34
是的,我剛看到它非常感謝你埃文 – arianna 2013-04-04 04:50:27