可以麻煩康我看一下下列的頁碼程式嗎?謝謝

edited 十月 2013 in 進階PHP討論
我先描述一下問題,

我可以用關鍵字查出資料庫資料,

而且首頁頁面正常顯示出資料庫中情況,

但是一跳入頁碼1以後的其它頁數頁碼時,

就會發現關鍵字的作用消失,

直接會顯示出資料庫中所有資料,

(第二頁就不會接續第一頁的關鍵字資料)

不知道大大是可以幫我解答一下,

需要在哪裡進行修改,



謝謝







<?php


session_start();
session_register('key_word');
$_SESSION = $_POST;
$key_word = $_SESSION;

function buildNavigation($pageNum_Recordset1,$totalPages_Recordset1,$prev_Recordset1,$next_Recordset1,$separator=" | ",$max_links=10, $show_page=true)
{
GLOBAL $maxRows_article_search,$totalRows_article_search;
$pagesArray = ""; $firstArray = ""; $lastArray = "";
if($max_links<2)$max_links=2;
if($pageNum_Recordset1<=$totalPages_Recordset1 && $pageNum_Recordset1>=0)
{
if ($pageNum_Recordset1 > ceil($max_links/2))
{
$fgp = $pageNum_Recordset1 - ceil($max_links/2) > 0 ? $pageNum_Recordset1 - ceil($max_links/2) : 1;
$egp = $pageNum_Recordset1 + ceil($max_links/2);
if ($egp >= $totalPages_Recordset1)
{
$egp = $totalPages_Recordset1+1;
$fgp = $totalPages_Recordset1 - ($max_links-1) > 0 ? $totalPages_Recordset1 - ($max_links-1) : 1;
}
}
else {
$fgp = 0;
$egp = $totalPages_Recordset1 >= $max_links ? $max_links : $totalPages_Recordset1+1;
}
if($totalPages_Recordset1 >= 1) {
#
# Searching for $_GET vars
#
$_get_vars = '';
if(!empty($_GET) || !empty($HTTP_GET_VARS)){
$_GET = empty($_GET) ? $HTTP_GET_VARS : $_GET;
foreach ($_GET as $_get_name => $_get_value) {
if ($_get_name != "pageNum_article_search") {
$_get_vars .= "&$_get_name=$_get_value";
}
}
}
$successivo = $pageNum_Recordset1+1;
$precedente = $pageNum_Recordset1-1;
$firstArray = ($pageNum_Recordset1 > 0) ? "<a href=\"$_SERVER[PHP_SELF]?pageNum_article_search=$precedente$_get_vars\">$prev_Recordset1</a>" : "$prev_Recordset1";
#
# page numbers
#
for($a = $fgp+1; $a <= $egp; $a++){
$theNext = $a-1;
if($show_page)
{
$textLink = $a;
} else {
$min_l = (($a-1)*$maxRows_article_search) + 1;
$max_l = ($a*$maxRows_article_search >= $totalRows_article_search) ? $totalRows_article_search : ($a*$maxRows_article_search);
$textLink = "$min_l - $max_l";
}
$_ss_k = floor($theNext/26);
if ($theNext != $pageNum_Recordset1)
{
$pagesArray .= "<a href=\"$_SERVER[PHP_SELF]?pageNum_article_search=$theNext$_get_vars\">";
$pagesArray .= "$textLink</a>" . ($theNext < $egp-1 ? $separator : "");
} else {
$pagesArray .= "$textLink" . ($theNext < $egp-1 ? $separator : "");
}
}
$theNext = $pageNum_Recordset1+1;
$offset_end = $totalPages_Recordset1;
$lastArray = ($pageNum_Recordset1 < $totalPages_Recordset1) ? "<a href=\"$_SERVER[PHP_SELF]?pageNum_article_search=$successivo$_get_vars\">$next_Recordset1</a>" : "$next_Recordset1";
}
}
return array($firstArray,$pagesArray,$lastArray);
}
require_once('../Connections/workerwall.php');
$maxRows_article_search = 20;
$pageNum_article_search = 0;
if (isset($_GET)) {
$pageNum_article_search = $_GET;
}
$startRow_article_search = $pageNum_article_search * $maxRows_article_search;
$key_article_search = "%";
if (isset($_SESSION)) {
$key_article_search = (get_magic_quotes_gpc()) ? $_SESSION : addslashes($_SESSION);
}
mysql_select_db($database_workerwall, $workerwall);
$query_article_search = "SELECT * FROM article_subject WHERE article_content LIKE '%".$key_word."%' ORDER BY inputdate DESC";
$query_limit_article_search = sprintf("%s LIMIT %d, %d", $query_article_search, $startRow_article_search, $maxRows_article_search);
$article_search = mysql_query($query_limit_article_search, $workerwall) or die(mysql_error());
$row_article_search = mysql_fetch_assoc($article_search);
if (isset($_GET)) {
$totalRows_article_search = $_GET;
} else {
$all_article_search = mysql_query($query_article_search);
$totalRows_article_search = mysql_num_rows($all_article_search);
}
$totalPages_article_search = ceil($totalRows_article_search/$maxRows_article_search)-1;
?>

<div>
<h1 align="center" class="style34">精 彩 文 章 區 目 錄</h1>
<table width="690" border="0" align="center" cellpadding="1" cellspacing="2" bordercolor="#333333">
<tr valign="middle" height="30">
<td width="30%" valign="middle" align="left">

<form id="form1" method="post" action="article_search_index.php">
<span class="style37" valign="middle">文章關鍵字查詢</span><br />
<label>
<input name="key_word" type="text" size="16" maxlength="16" />
</label>
<label>
<input type="submit" name="Submit3" value="查詢" />
</label>
</form></td>
<td width="20%" align="center"><div class="style37"><a href="../articles/article_post.php"><img src='../images/article_post.jpg' /></a></div></td>
<td width="20%" align="center"><div class="style37"><a href="javascript:history.go(-1)"><img src='../images/backward.jpg' /></a></div></td>
<td width="30%" align="right"><div><span class="style37">目前共有</span><span class="style29"><? echo ($totalRows_article_search); ?></span><span class="style37">篇文章</span></div></td>
</tr>
<tr height="30">
<td colspan="4">
<div align="center">
<?php
# variable declaration
$prev_article_search = "上一頁 ";
$next_article_search = " 下一頁";
$separator = " | ";
$max_links = 20;
$pages_navigation_article_search = buildNavigation($pageNum_article_search,$totalPages_article_search,$prev_article_search,$next_article_search,$separator,$max_links,true);

print $pages_navigation_article_search[0];
print $pages_navigation_article_search[1];
print $pages_navigation_article_search[2];
?>
</div>
</td>
</tr>
</table>
<table width="690" border="2" align="center" cellpadding="1" cellspacing="2" bordercolor="#333333">
<tr bgcolor="#0066CC" height="35">
<td width="44%" height="24" align="center" bordercolor="#333333" bgcolor="#FFFF99"><div align="center" class="style29">文 章 主 題</div></td>
<td width="15%" align="center" bordercolor="#333333" bgcolor="#FFFF99"><div align="center" class="style29">首次發表</div></td>
<td width="12%" align="center" bordercolor="#333333" bgcolor="#FFFF99"><div align="center" class="style29">發表人</div></td>
<td width="7%" align="center" bordercolor="#333333" bgcolor="#FFFF99"><div align="center" class="style29">人氣</div></td>
<td width="7%" align="center" bordercolor="#333333" bgcolor="#FFFF99"><div align="center" class="style29">回應</div></td>
<td width="15%" align="center" bordercolor="#333333" bgcolor="#FFFF99"><div align="center" class="style29">最後回應</div></td>
</tr>
<?php do { ?>
<tr>
<td width="44%" align="left" height="35"><a href='article_show.php?article_no=<? echo ($row_article_search);?>'><?php echo $row_article_search; ?></a></td>
<td width="15%" align="center" height="35"><?php echo (substr($row_article_search,0,10)); ?></td>
<td width="12%" align="center" height="35"><?php echo $row_article_search; ?></td>
<td width="7%" align="center" height="35"><?php echo $row_article_search; ?></td>
<td width="7%" align="center" height="35"><?php echo $row_article_search; ?></td>
<td width="15%" align="center" height="35"><?php echo (substr($row_article_search,0,10)); ?></td>
<?php } while ($row_article_search = mysql_fetch_assoc($article_search)); ?></tr>
</table>
</div>
<?php mysql_free_result($article_search);?>

原始討論: http://twpug.net/x/modules/newbb/viewtopic.php?topic_id=3446

評論

Sign In or Register to comment.