Php 带分页的搜索引擎:第1页的问题
请帮助我,我尝试创建带分页的搜索引擎,除了单击返回到page1的链接外,一切似乎都很好,它从mysql有序地拉出数据,而不是从我输入的查询中,但这只发生在我的第一页上。当我单击时,我真的需要这方面的帮助Php 带分页的搜索引擎:第1页的问题,php,mysql,pagination,Php,Mysql,Pagination,请帮助我,我尝试创建带分页的搜索引擎,除了单击返回到page1的链接外,一切似乎都很好,它从mysql有序地拉出数据,而不是从我输入的查询中,但这只发生在我的第一页上。当我单击时,我真的需要这方面的帮助 <?php session_start(); error_reporting(E_ERROR); $link = mysql_connect("localhost","root","1234"); mysql_query("Use igstore"); $pagesquery = mysq
<?php
session_start();
error_reporting(E_ERROR);
$link = mysql_connect("localhost","root","1234");
mysql_query("Use igstore");
$pagesquery = mysql_query("SELECT COUNT('creatorid') FROM `creator`");
$pages = ceil(mysql_result($pagesquery, 0)/$perpage);
$page = (isset($_GET['page']))?(int)$_GET['page']:1;
$start = ($page-1)*$perpage;
//to filter from inputted data from textbox and combobox
if($value == null&&$genre == null&&$star == null){
$sql = "SELECT * FROM `creator` WHERE `title` LIKE '%$find%' OR `creatorid` LIKE '$item' LIMIT $start, $perpage";}
else if($value != null){
$sql = "SELECT * FROM `creator` WHERE `aprice` = '$value' OR `creatorid` LIKE '$item' LIMIT $start, $perpage";}
else if($genre != null){
$sql = "SELECT * FROM `creator` WHERE `type` = '$genre' OR `creatorid` LIKE '$item' LIMIT $start, $perpage";}
else if($star != null){
$sql = "SELECT * FROM `creator` WHERE `popular` = '$star' OR `creatorid` LIKE '$item' LIMIT $start, $perpage";}
$result = mysql_query($sql) or die(mysql_error());
while($_GET = mysql_fetch_array($result)){
$head = $_GET['title'];
$def = $_GET['description'];
$pric = $_GET['aprice'];
$blob = $_GET['img1'];
echo"<html>";
echo'<table height="180" width="1300">';
echo"<tr>";
echo'<th align="center">';
echo'<div class="ab">';
echo'<img src="data:image/jpeg;base64,'.base64_encode($blob).'"/ width="150px" height="150px">';
echo'</div>';
echo'</th>';
echo'<th align="left">';
echo'<div class="container">';
echo"<a href='#'><h3>$head</h3></a>";
echo"<textarea style='resize: none;border: none' rows='5' cols='60' readonly>$def</textarea><br>";
echo"<label class='control-label col-sm-2'><h5>ราคา: $pric</h5></label><br><br>";
echo"</div>";
echo'</th>';
echo"</tr>";
echo'</table>';
echo'<hr width="100%">';
echo"</html>";
}
//this is for showing page number
$prev = $page - 1;
$next = $page + 1;
echo "<a href='result.php?page=$prev' style='display: inline-block';>Prev</a>";
for($index=1;$index<=$pages;$index++){
echo ($page == $index)?'<b><a href="?page='.$index.'" style="display: inline-block"; >'.$index.'</a> </b>':'<a href="?page='.$index.'" style="display: inline-block"; >'.$index.'</a>';
}
echo "<a href='result.php?page=$next' style='display: inline-block';>Next</a>";
?>
您在哪里声明了$perpage
变量?您的$pagesquery
也应该与下面的查询具有相同的条件(当然限制除外)。我在顶部声明,但在发布pagequery时,它可能会被意外删除。对于pagequery,我使用select count提供了我拥有的总记录,但您知道我的第一页吗?