0

ページが適切に読み込まれ、結果がテーブルに表示されます (最初のページから正しく渡された変数/値)。設定された「制限」に従って正しい数のレコードを使用します。ページネーションは、レコードをページに正しく分割します。

コードで助けが必要な 2 つのこと:

1) ページネーションは「前の 1 2 3 ... 6 7 8 次の」を表示することになっています。代わりに「前へ 1 2 3 4 5 6 7 8 次へ」と表示されます。コードは私には問題ないようです-オンラインでさまざまな投稿を調べてみましたが、これを解決するものは見つかりませんでした.

2) ページが結果をロードした後、次のページをクリックすると、次のページに移動しますが、レコードは表示されません (空白のテーブル; ただし、他のすべての静的アイテムが表示されます)。確認したところ、「ページ」変数が次のページに渡されます。エラーも発生しません。

私は PHP の知識が限られており、いくつかの投稿を読みましたが、解決できませんでした。

以下はコードです - 誰かが助けてくれれば、私は大いに感謝します。ファイル名: display.php 変数は前のファイルから渡されます: index.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']; ?>&nbsp;<?php echo $row['VehModel']; ?>&nbsp;(<?php echo $row['VehYear']; ?>)</h1>
    <NormalText><br>
        <?php echo $row['VehMileage']; ?>kms&nbsp;-&nbsp;<?php echo $row['VehTransmission']; ?>&nbsp;-&nbsp;<?php echo $row['VehEngine']; ?>cc 
        <br>
        <?php echo $row['VehCategory']; ?>&nbsp;-&nbsp;<?php echo $row['VehColour']; ?>&nbsp;-&nbsp;<?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>
4

1 に答える 1