Php 记录只显示在第一页
页面以表格形式正确加载结果(从初始页面正确传递变量/值);根据设定的“限制”记录数量正确;分页将记录正确地划分为多页 代码中有两件事我需要帮助: 1) 分页应该显示“以前的12 3。。。6 7 8下一个';而是显示“上一个12345678下一个”。代码对我来说似乎很好-尝试在网上查找各种帖子,但没有找到任何解决方法 2) 页面加载结果后,我单击下一页,它进入下一页,但不显示任何记录(空白表;但显示所有其他静态项)。我进行了检查,“page”变量被传递到下一页。它也不会带来任何错误 我对PHP的了解有限,读过几篇文章,但无法解决问题 下面是代码-如果有人能提供帮助,我将不胜感激。 文件名:display.php 变量从上一个文件:index.php传递Php 记录只显示在第一页,php,pagination,Php,Pagination,页面以表格形式正确加载结果(从初始页面正确传递变量/值);根据设定的“限制”记录数量正确;分页将记录正确地划分为多页 代码中有两件事我需要帮助: 1) 分页应该显示“以前的12 3。。。6 7 8下一个';而是显示“上一个12345678下一个”。代码对我来说似乎很好-尝试在网上查找各种帖子,但没有找到任何解决方法 2) 页面加载结果后,我单击下一页,它进入下一页,但不显示任何记录(空白表;但显示所有其他静态项)。我进行了检查,“page”变量被传递到下一页。它也不会带来任何错误 我对PHP的了
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<!-- INCLUDE THE CSS STYLESHEET FILE -->
<link href="Stylesheet/vehicles_stylesheet.css" rel="stylesheet" type="text/css">
<link href="Stylesheet/style.css" rel="stylesheet" type="text/css">
<?php
include("header.php");
?>
<script language="JavaScript" type="text/JavaScript">
====some javascript code here ===
</script>
</head>
<body bgcolor="#DADADA" onLoad="MM_preloadImages('images/ContactSellerOVR.gif','images/SearchAgainOVR.jpg')">
<?php
//Get Values from previous page
@$VehName = $_POST['VehName'];
@$VehModel = $_POST['VehModel'];
if ($VehModel=='')
{
$VehModel="%";
}
@$YearFrom = $_POST['YearFrom'];
if ($YearFrom=='')
{
$YearFrom=1960;
}
@$YearTo = $_POST['YearTo'];
if ($YearTo=='')
{
$YearTo=date('Y');
}
@$Price = $_POST['Price'];
if ($Price=='')
{
$Price="%";
}
@$Location = $_POST['Location'];
if ($Location=='')
{
$Location="%";
}
switch ($Price)
{
case "A":
$PriceSearch = "' AND VehPrice BETWEEN 0 AND 500000 ";
break;
case "B":
$PriceSearch = "' AND VehPrice BETWEEN 500000 AND 1000000 ";
break;
case "C":
$PriceSearch = "' AND VehPrice BETWEEN 1000000 AND 2000000 ";
break;
case "D":
$PriceSearch = "' AND VehPrice BETWEEN 2000000 AND 3000000 ";
break;
case "E":
$PriceSearch = "' AND VehPrice BETWEEN 3000000 AND 5000000 ";
break;
case "F":
$PriceSearch = "' AND VehPrice BETWEEN 5000001 AND 99000000 ";
break;
default:
$PriceSearch = "' AND VehPrice BETWEEN 0 AND 99000000 ";
}
?>
<table width="1000" cellspacing="0" cellpadding="4" align="center" border="0" bgcolor="#FFFFFF">
<tr>
<td align="center">
<a href="index.php" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Search Again','','images/SearchAgainOVR.jpg',1)"><img src="images/SearchAgain.jpg" name="Search Again" width="160" height="40" border="0" align="middle"></a>
</td>
</tr>
</table>
<?php
include('Connections/VehicleConn.php');
$tbl_name="vehicledetails"; // table name
$adjacents = 4; // How many adjacent pages should be shown on each side
// Get total number of rows in data table
$query = "SELECT COUNT(*) as num FROM vehicledetails WHERE VehName LIKE '" . $VehName .
"' AND VehModel LIKE '" . $VehModel . "'
AND VehYear BETWEEN '" . $YearFrom . "' AND '" . $YearTo .
$PriceSearch . " ORDER BY VehDateadded DESC" ;
$total_pages = mysql_fetch_array(mysql_query($query));
$total_pages = $total_pages['num'];
/* Setup vars for query. */
$targetpage = "display.php"; //the name of this file
$limit = 3; // how many items to show per page
$page = isset($_GET['page']) ? $_GET['page'] : 0;
if($page)
$start = ($page - 1) * $limit; //first item to display on this page
else
$start = 0; //if no page var is given, set start to 0
// Get data
$sql = "SELECT * FROM vehicledetails WHERE VehName LIKE '" . $VehName .
"' AND VehModel LIKE '" . $VehModel . "'
AND VehYear BETWEEN '" . $YearFrom . "' AND '" . $YearTo .
$PriceSearch . " ORDER BY VehDateadded DESC LIMIT " . $start . ", " . $limit ;
$result = mysql_query($sql) or die(mysql_error());
// Setup page vars for display
if ($page == 0) $page = 1; //if no page var is given, default to 1
$prev = $page - 1; //previous page is page - 1
$next = $page + 1; //next page is page + 1
$lastpage = ceil($total_pages/$limit); //lastpage is = total pages / items per page, rounded up.
$lpm1 = $lastpage - 1; //last page minus 1
/*
Apply rules and draw the pagination object
Save the code to a variable in case required to draw it more than once.
*/
$pagination = "";
if($lastpage > 1)
{
$pagination .= "<div class=\"pagination\">";
//previous button
if ($page > 1)
$pagination.= "<a href=\"$targetpage?page=$prev\">Previous</a>";
else
$pagination.= "<span class=\"disabled\">Previous</span>";
//pages
if ($lastpage < 7 + ($adjacents * 2)) //not enough pages to bother breaking it up
{
for ($counter = 1; $counter <= $lastpage; $counter++)
{
if ($counter == $page)
$pagination.= "<span class=\"current\">$counter</span>";
else
$pagination.= "<a href=\"$targetpage?page=$counter\">$counter</a>";
}
}
elseif($lastpage > 5 + ($adjacents * 2)) //enough pages to hide some
{
//close to beginning; only hide later pages
if($page < 1 + ($adjacents * 2))
{
for ($counter = 1; $counter < 4 + ($adjacents * 2); $counter++)
{
if ($counter == $page)
$pagination.= "<span class=\"current\">$counter</span>";
else
$pagination.= "<a href=\"$targetpage?page=$counter\">$counter</a>";
}
$pagination.= "...";
$pagination.= "<a href=\"$targetpage?page=$lpm1\">$lpm1</a>";
$pagination.= "<a href=\"$targetpage?page=$lastpage\">$lastpage</a>";
}
//in middle; hide some front and some back
elseif($lastpage - ($adjacents * 2) > $page && $page > ($adjacents * 2))
{
$pagination.= "<a href=\"$targetpage?page=1\">1</a>";
$pagination.= "<a href=\"$targetpage?page=2\">2</a>";
$pagination.= "...";
for ($counter = $page - $adjacents; $counter <= $page + $adjacents; $counter++)
{
if ($counter == $page)
$pagination.= "<span class=\"current\">$counter</span>";
else
$pagination.= "<a href=\"$targetpage?page=$counter\">$counter</a>";
}
$pagination.= "...";
$pagination.= "<a href=\"$targetpage?page=$lpm1\">$lpm1</a>";
$pagination.= "<a href=\"$targetpage?page=$lastpage\">$lastpage</a>";
}
//close to end; only hide early pages
else
{
$pagination.= "<a href=\"$targetpage?page=1\">1</a>";
$pagination.= "<a href=\"$targetpage?page=2\">2</a>";
$pagination.= "...";
for ($counter = $lastpage - (2 + ($adjacents * 2)); $counter <= $lastpage; $counter++)
{
if ($counter == $page)
$pagination.= "<span class=\"current\">$counter</span>";
else
$pagination.= "<a href=\"$targetpage?page=$counter\">$counter</a>";
}
}
}
//next button
if ($page < $counter - 1)
$pagination.= "<a href=\"$targetpage?page=$next\">Next</a>";
else
$pagination.= "<span class=\"disabled\">Next</span>";
$pagination.= "</div>\n";
}
?>
<table width="1000" cellspacing="0" cellpadding="4" align="center" border="1" bordercolor="#F7F7F7" bgcolor="#FFFFFF">
<?php
// While loop to display records
while($row = mysql_fetch_array($result))
{
?>
<tr>
<td bgcolor="#FFFFFF" width="320">
<blockquote>
<h1><?php echo $row['VehName']; ?> <?php echo $row['VehModel']; ?> (<?php echo $row['VehYear']; ?>)</h1>
<NormalText><br>
<?php echo $row['VehMileage']; ?>kms - <?php echo $row['VehTransmission']; ?> - <?php echo $row['VehEngine']; ?>cc
<br>
<?php echo $row['VehCategory']; ?> - <?php echo $row['VehColour']; ?> - <?php echo $row['VehFuel']; ?>
<br>
Vehicle Location: <?php echo $row['VehLocation']; ?>
<br>
<strong>Price: KShs. <?php echo $row['VehPrice']; ?> </strong><br>
<br>
</NormalText>
<form name="displaycontact" action="contactseller.php" target="_blank" method="post">
<input type="hidden" name="ID" value="<?php echo $row['VehID']; ?>">
<input type="hidden" name="NAME" value="<?php echo $row['VehName']; ?>">
<input type="hidden" name="MODEL" value="<?php echo $row['VehModel']; ?>">
<input type="hidden" name="YEAR" value="<?php echo $row['VehYear']; ?>">
<input type="hidden" name="MILEAGE" value="<?php echo $row['VehMileage']; ?>">
<input type="hidden" name="TRANSMISSION" value="<?php echo $row['VehTransmission']; ?>">
<input type="hidden" name="ENGINE" value="<?php echo $row['VehEngine']; ?>">
<input type="hidden" name="CATEGORY" value="<?php echo $row['VehCategory']; ?>">
<input type="hidden" name="COLOUR" value="<?php echo $row['VehColour']; ?>">
<input type="hidden" name="FUEL" value="<?php echo $row['VehFuel']; ?>">
<input type="hidden" name="LOCATION" value="<?php echo $row['VehLocation']; ?>">
<input type="hidden" name="PRICE" value="<?php echo $row['VehPrice']; ?>">
<input type="hidden" name="CONTACTNAME" value="<?php echo $row['VehContactname']; ?>">
<input type="hidden" name="CONTACTEMAIL" value="<?php echo $row['VehContactemail']; ?>">
<input type="hidden" name="CONTACTTEL" value="<?php echo $row['VehContacttel']; ?>">
<input type="submit" name="Submit" value="Contact Seller"> </form>
</blockquote>
</td>
<td bgcolor="#FFFFFF" width="680" align="center">
<a href="images/<?php echo $row['VehImage1']; ?>" rel="lightbox" title=""><img src="images/<?php echo $row['VehImage1']; ?>" align="middle" border="0" width="100" height="100"></a><a href="images/<?php echo $row['VehImage2']; ?>" rel="lightbox" title=""><img src="images/<?php echo $row['VehImage2']; ?>" align="middle" border="0" width="100" height="100"></a><a href="images/<?php echo $row['VehImage3']; ?>" rel="lightbox" title=""><img src="images/<?php echo $row['VehImage3']; ?>" align="middle" border="0" width="100" height="100"></a><a href="images/<?php echo $row['VehImage4']; ?>" rel="lightbox" title=""><img src="images/<?php echo $row['VehImage4']; ?>" align="middle" border="0" width="100" height="100"></a>
</td>
</tr>
<?php
}
?>
</table>
<table width="1000" cellspacing="0" cellpadding="4" align="center" bgcolor="#FFFFFF">
<tr align="center">
<td align="center">
<?php
echo $pagination
?>
</td>
</tr>
</table>
<?php
include("footer.php");
?>
</body>
</html>
==这里有一些javascript代码===
)
kms--cc
- -
车辆位置:
价格:千先令
休闲代码对我有用
include('connect-db.php');
// number of results to show per page
$per_page = 150;
// figure out the total pages in the database
if ($result = $mysqli->query(""SELECT COUNT(*) as num FROM vehicledetails WHERE VehName LIKE '" . $VehName .
"' AND VehModel LIKE '" . $VehModel . "'
AND VehYear BETWEEN '" . $YearFrom . "' AND '" . $YearTo .
$PriceSearch . " ORDER BY VehDateadded DESC" ; "))
{
if ($result->num_rows != 0)
{
$total_results = $result->num_rows;
// ceil() returns the next highest integer value by rounding up value
if necessary
$total_pages = ceil($total_results / $per_page);
// check if the 'page' variable is set in the URL (ex: view-paginated
.php?page=1)
if (isset($_GET['page']) && is_numeric($_GET['page']))
{
$show_page = $_GET['page'];
// make sure the $show_page value is valid
if ($show_page > 0 && $show_page <= $total_pages)
{
$start = ($show_page -1) * $per_page;
$end = $start + $per_page;
}
else
{
// error - show first set of results
$start = 0;
$end = $per_page;
}
}
else
{
// if page isn't set, show first set of results
$start = 0;
$end = $per_page;
}
// display pagination
echo "<p><a href='view.php'>View All</a> | <b>View Page:</b> ";
for ($i = 1; $i <= $total_pages; $i++)
{
if (isset($_GET['page']) && $_GET['page'] == $i)
{
echo $i . " ";
}
else
{
echo "<a href='view-paginated.php?page=$i'>$i</a> ";
}
}
echo "</p>";
<your code to display data>
include('connect-db.php');
//每页要显示的结果数
每页$150;
//计算出数据库中的总页面数
如果($result=$mysqli->query(“'SELECT COUNT(*)as num FROM vehicledetails WHERE VehName LIKE'”。$VehName。
“‘和VehModel相似’。$VehModel.”
在“.$YearFrom.”和“.$YearTo”之间移动。
$PriceSearch.“按VehDateadded DESC订购”;“”)
{
如果($result->num_rows!=0)
{
$total\u results=$result->num\u行;
//ceil()通过向上舍入值返回下一个最高整数值
必要时
$total_pages=ceil($total_results/$per_pages);
//检查URL中是否设置了“page”变量(例如:视图分页
.php?第页=1)
如果(isset($\u GET['page'])和&是数字($\u GET['page']))
{
$show_page=$_GET['page'];
//确保$show\u页面值有效
如果($show_page>0&&$show_page)您在这里给出的代码相当长。提示:尝试并集中精力于中心问题。然后是另一个“离题”我想到的提示是:当您想为表单变量设置默认值时,我发现以下方法很有用:首先将变量设置为默认值,然后提取$\u请求或$\u POST
数组,如$VehName='noname';$VehModel=$Price=$Location='%';$YearFrom=1960;$YearTo=date('Y'));extract($_POST);
。谢谢,非常有用的建议-将应用于我的代码我尝试使用您的代码,我收到以下错误:解析错误:语法错误,display.php中的意外T_字符串在第118行第118行是:if($result=$mysqli->query(““选择COUNT(*)as num FROM vehicledetails WHERE VehName LIKE.”“$VehName。我注意到代码中缺少两个右括号},我已经添加了它们,但是仍然存在错误。有没有解决该错误的建议?