dongyun6229 2015-05-01 05:12
浏览 29

搜索分页,但搜索不起作用[重复]

I have this code for test3.php, with pagination and search, the pagination is working fine but the search is not working. I don't know what is the problem in my code. Can somebody help me with my search function. I've searched the internet but I couldn't find any solution about my problem. Please help me about it. Thank you.

<html>
<head>
<title>Pagination</title>



<body>

<form name="search_form" method="POST" action="">

Search:<input type="text" name="search_box" value="" />
<input type="submit" name="search" value="search the table" />

</form>

<?php

mysql_connect("localhost","root","") or die (mysql_error());
mysql_select_db("region_survey") or die (mysql_error());

$sql = mysql_query("SELECT * FROM municipality ORDER BY id ASC");

$nr = mysql_num_rows($sql);  
if (isset($_GET['pn'])) { 
$pn = preg_replace('#[^0-9]#i', '', $_GET['pn']); 
} else { 
$pn = 1;
} 

$itemsPerPage = 10; 

$lastPage = ceil($nr / $itemsPerPage);

if ($pn < 1) {
$pn = 1;
}   else if ($pn > $lastPage) { 
$pn = $lastPage; 
} 

$centerPages = "";
$sub1 = $pn - 1;
$sub2 = $pn - 2;
$add1 = $pn + 1;
$add2 = $pn + 2;
if ($pn == 1) {
$centerPages .= '&nbsp; <span class="pagNumActive">' . $pn . '</span> &nbsp;';
$centerPages .= '&nbsp; <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $add1 . '">' . $add1 . '</a> &nbsp;';
} else if ($pn == $lastPage) {
    $centerPages .= '&nbsp; <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $sub1 . '">' . $sub1 . '</a> &nbsp;';
    $centerPages .= '&nbsp; <span class="pagNumActive">' . $pn . '</span> &nbsp;';
} else if ($pn > 2 && $pn < ($lastPage - 1)) {
    $centerPages .= '&nbsp; <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $sub2 . '">' . $sub2 . '</a> &nbsp;';
    $centerPages .= '&nbsp; <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $sub1 . '">' . $sub1 . '</a> &nbsp;';
    $centerPages .= '&nbsp; <span class="pagNumActive">' . $pn . '</span> &nbsp;';
    $centerPages .= '&nbsp; <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $add1 . '">' . $add1 . '</a> &nbsp;';
    $centerPages .= '&nbsp; <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $add2 . '">' . $add2 . '</a> &nbsp;';
}   else if ($pn > 1 && $pn < $lastPage) {
    $centerPages .= '&nbsp; <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $sub1 . '">' . $sub1 . '</a> &nbsp;';
    $centerPages .= '&nbsp; <span class="pagNumActive">' . $pn . '</span> &nbsp;';
    $centerPages .= '&nbsp; <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $add1 . '">' . $add1 . '</a> &nbsp;';
    }

$limit = 'LIMIT ' .($pn - 1) * $itemsPerPage .',' .$itemsPerPage; 

$sql2 = mysql_query("SELECT * FROM municipality ORDER BY id ASC $limit"); 

$paginationDisplay = ""; 

if ($lastPage != "1"){

$paginationDisplay .= 'Page <strong>' . $pn . '</strong> of ' . $lastPage. '&nbsp;  &nbsp;  &nbsp; ';

if ($pn != 1) {
    $previous = $pn - 1;
$paginationDisplay .=  '&nbsp;  <a href="' . $_SERVER['PHP_SELF'] . '? pn=' . $previous . '"> Back</a> ';
} 

$paginationDisplay .= '<span class="paginationNumbers">' . $centerPages . '</span>';

if ($pn != $lastPage) {
    $nextPage = $pn + 1;
$paginationDisplay .=  '&nbsp;  <a href="' . $_SERVER['PHP_SELF'] . '?  pn=' . $nextPage . '"> Next</a> ';
} 
}

$outputList = '';

?>
<div id="tables">
<table>

    <tr>
        <th>LO Name</th>
        <th>Province</th>
        <th>Location</th>
        <th>Action</th>
        <th>Update</th>
    </tr>


<?php

while($row = mysql_fetch_array($sql2)) {
    $id=$row['id'];
?>

    <tr>
        <td><?php echo $row['id']; ?></td>
        <td><?php echo $row['province_id']; ?></td>
        <td><?php echo $row['municipality_name']; ?></td>
        <td><input name="selector[]" type="checkbox"
id="checkbox[]" value="<?php echo $row['id'];?>"></td>
<td><a href="update.php<?php echo '?id='.$row['id']; ?>">Edit</a>     </td>

    </tr>
<?php
}
?>
</table>


<?php
$con = mysql_connect("localhost","root","");
if (!$con) {
die('Could not connect: ' . mysql_error());
}

mysql_select_db("region_survey", $con);

$result = mysql_query("select count(1) FROM municipality");
$row = mysql_fetch_array($result);


$total = $row[0];
echo "Total rows: " . $total;

mysql_close($con);
?>

<br />
<br />
<?php echo $paginationDisplay; ?>
</body>
</html>
</div>
  • 写回答

1条回答 默认 最新

  • douyou2732 2015-05-01 05:19
    关注

    You have not add the keyword on which the query will search in your database use below query

    mysql_query("SELECT * FROM municipality where <your-field-name> LIKE %".$_POST['<your input box name>']." ORDER BY id ASC");

    Hope this will help you in solving your problem

    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题