Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8625705
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T07:51:17+00:00 2026-06-12T07:51:17+00:00

I have tried a few things but cant seem to implement pagination properly, can

  • 0

I have tried a few things but cant seem to implement pagination properly, can someone point me in the right direction and give me a few code examples of how i can properly implement pagination in my code

<?php
session_start();

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

<link rel="stylesheet" type="text/css" href="stylesheet.css">
<link href="/lightbox/css/lightbox.css" rel="stylesheet" />
<link rel="stylesheet" href="img/reveal.css">


<script src="/lightbox/js/jquery-1.7.2.min.js"></script>
<script src="/lightbox/js/lightbox.js"></script>
<script src="img/jquery.min.js" type="text/javascript"></script>
<script src="img/jquery.reveal.js" type="text/javascript"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.0/jquery.min.js"     type="text/javascript"></script>

<style type="text/css">

#divspace {
position: relative;
width: 100%;
height: 50px;
z-index: -9999;
vertical-align bottom;


 }

 #divspace1 {
position: relative;
width: 100%;
height: 50px;
z-index: -9999;
vertical-align: bottom;
padding-left: 400px;


}


#search1 {
position: absolute;
width: 203px;
height: 30px;
z-index: -9999;
vertical-align: bottom;
left: 832px;
top: 1px;
z-index: 9999;
}

 #text1 {
position: absolute;
width: 203px;
height: 30px;
z-index: -9999;
vertical-align: bottom;
top: 13px;
z-index: 9999;
left: 268px;
font-family: Tahoma, Geneva, sans-serif;
font-weight: bold;
color: #FFF;
font-style: italic;
font-size: 22px;
 }

 #apDiv1 {
position:absolute;
width:560px;
height:27px;
z-index:1;
left: 93px;
top: 247px;
}

#cat {
position:absolute;
width:227px;
height:500px;
z-index:1;
left: 3px;
top: 48px;
background-color: #FFF;
font-family:"Lucida Console", Monaco, monospace;
 }


 .container1 {
position:relative;
padding: 0 20px 0 20px;
margin: auto;
width: 1000px;
background-image: url(images/skyblue.png);
margin-top: 20px;
margin-bottom: 20px;
padding-bottom: 300px;
-moz-border-radius: 8px;
border-radius: 8px;

 }


 .label{
text-align:right;
  }
  #submit{
text-align:center;
   }

</style>
<script type = "text/javascript">

function myfunction(url)
  {
 window.location.href = url;
 }
</script>

<script type="text/javascript">
$(document).ready(function(){    
$(".expanderHead").click(function(){
    var $exsign = $("#expanderSign");
    $(this).find("#expanderContent").slideToggle();
    $exsign.html($exsign.text() == '+' ? '-': '+');   
    // simplify your if/else into one line using ternary operator
    // if  $exsign.text() == "+" then use "-" else "+"
 });    
});
</script>



</head>
<body>
<div id="header">
  <div id="fb-root"></div>
<script>(function(d, s, id) {
  var js, fjs = d.getElementsByTagName(s)[0];
  if (d.getElementById(id)) return;
  js = d.createElement(s); js.id = id;
  js.src = "//connect.facebook.net/en_GB/all.js#xfbml=1&appId=439699742746900";
  fjs.parentNode.insertBefore(js, fjs);
    }(document, 'script', 'facebook-jssdk'));</script>


<div id="search">
  <center>
<form method="GET" action="search.php" style= "padding: 1px;">
<input name="search" id="s" type="text" value="<?php echo $_GET['search']; ?>" size="20" />

<select name="category" id="category" >
                <?php if(isset($_GET['submit'])) { ?>
                <option value="<?php echo $_GET['category']; ?>" selected="selected"><?php echo $_GET['category']; ?></option>
                <?php }else{ ?>
                <option value=""> -- select -- </option>
                <?php } ?>
                <option value="">All</option>
                <option value="Books">Books</option>
                <option value="Textbooks">TextBooks</option>
                <option value="Tickets">Tickets</option>
                <option value="Electronics">Electronics</option>
                <option value="Clothing">Clothing</option>
                <option value="Accessories">Accessories</option>
                <option value="Furniture">Furniture</option>
                <option value="Imagery">Imagery</option>
                <option value="Business">Business</option>
                <option value="Clothing">Clothing</option>
                <option value="Multi">Multimedia</option>
    </select>

    <select name="university" id="university" >
                <option value="">Aston University</option>
    </select>       
    <input id="searchSubmit" type="submit" value="" name="submit"/>

  </form>
  </center>
</div>


<div id="imagelogo" onclick = "window.location.href = 'index.php'" > 

  <p> Buy and sell stuff around University</p>
</div>

<ul id="navigation" name="navigation">
  <li id="nav-home"><a href="index.php">Home | </a><a href="search.php">Search | </a><a href="#">Selling | </a><a href="#">Buying | </a><a href="#">FAQ | </a><a href="#">Contact</a>    </li>
</ul>

<div id="account">

  <?php
if( isset( $_SESSION['username'] ) ){

   echo "<a href='securedpage1.php'>My Account</a><img src='images/uni-icon.png' width='30' height='18' style='vertical-align: middle;'/>";

}else{

      echo "<a href='login.php' >Login</a><img src='images/uni-icon.png' width='30' height='18' style='vertical-align: middle;'/>";
}
        ?>

    </div>

    <div id="registerlogout">
 <?php
 if( isset( $_SESSION['username'] ) ){
   echo "<a href='logout.php'>Logout</a>";

}else{

  echo "<a href='register.php'> Register</a>";
    }
        ?>
</div>






<center>
<center>

</div>
<div class="container1">
<div id="cat">
  <table width="225" border="1" cellspacing="10" cellpadding="10">
<tr>
<td>Accessories</td>
  </tr>
  <tr>
    <td>Accommodation</td>
  </tr>
  <tr>
        <td>Books</td>
  </tr>
  <tr>
    <td>Business</td>
  </tr>
  <tr>
    <td>Clothing</td>
  </tr>
  <tr>
    <td>Electronics</td>
  </tr>
  <tr>
    <td>Furniture</td>
  </tr>
  <tr>
        <td>Imagery</td>
  </tr>
  <tr>
    <td>Multimedia</td>
  </tr>
  <tr>
<td>Services</td>
      </tr>
<tr>
<td>Tickets</td>
  </tr>
</table>
</div>

<div id="text1">Items For Sale:

</div>

<div id="search1">
<form method="GET" action="search.php" style= "padding: 1px;">
<select name="price" id="price" >
                <?php if(isset($_GET['submit'])) { ?>
                <option value="<?php echo $_GET['price']; ?>" selected="selected"><?php echo $_GET['price']; ?></option>
                <?php }else{ ?>
                <option value=""> -- select -- </option>
                <?php } ?>
                <option value=""></option>
                <option value="DESC">Highest to Lowest</option>
                <option value="ASC">Lowest to Highest</option>
    </select>
     <input id="searchSubmit" type="submit" value="" name="submit"/>
</form>
    </div>

<div id="divspace"></div>
<div style=" padding-left: 240px" ">


<?php

// Include database connection settings
include('config.php');
include('config.inc');



    // Check and set username
$username = (isset($_SESSION['username']) ? $_SESSION['username'] : 'guest');

// Check and set category
    $category = (!empty($_GET['category']) ? $_GET['category'] : null);

// Check and set search
if(!empty($_GET['search'])){
$search = $_GET['search'];
}else{
$search = null;
}

 // Check that $_GET['price'] is ASC if not set to DESC
// as static values its ok to directly put in the query 
 if(isset($_GET['price']) && $_GET['price'] == 'ASC'){
$price = 'ASC';
 }else{
$price = 'DESC';
}

if ($search !== null){

$sql = "SELECT * FROM people WHERE MATCH (lname,fname) AGAINST (:search IN BOOLEAN MODE)";

$q   = $conn->prepare($sql) or die("failed!");
// Bind the params to the placeholders
$q->bindParam(':search', $search, PDO::PARAM_STR);
$q->execute();
}

if ($search !== null && $category !== null){

$sql = "SELECT * FROM people WHERE MATCH (lname,fname) AGAINST (:search IN BOOLEAN MODE) AND category = :category";

$q   = $conn->prepare($sql) or die("failed!");
// Bind the params to the placeholders
$q->bindParam(':search', $search, PDO::PARAM_STR);
$q->bindParam(':category', $category, PDO::PARAM_STR);
$q->execute();
}

if ($category !== null && $search !== null && isset($price)){

$sql = "SELECT   *
        FROM     people
        WHERE    MATCH (lname,fname) AGAINST (:search IN BOOLEAN MODE)
        AND      category = :category
        ORDER BY price ".$price;

$q = $conn->prepare($sql);
// Bind the params to the placeholders
$q->bindParam(':search', $search, PDO::PARAM_STR);
$q->bindParam(':category', $category, PDO::PARAM_STR);
$q->execute();
}

if ($category == null && $search !== null && isset($price)){

$sql = "SELECT   *
        FROM     people
        WHERE    MATCH (lname,fname) AGAINST (:search IN BOOLEAN MODE)

        ORDER BY price ".$price;

$q = $conn->prepare($sql);
// Bind the params to the placeholders
$q->bindParam(':search', $search, PDO::PARAM_STR);
$q->execute();
}

if ($q){

//declaring counter
    $count=0;
    while($r = $q->fetch(PDO::FETCH_ASSOC)){
    $row = $r;

    $fname = $row['fname'];
    $lname = $row['lname'];
    $firstname = $row['firstname'];
    $surname = $row['surname'];
    $expire = $row['expire'];

    $oDate = strtotime($row['expire']);
    $sDate = date("d/m/y",$oDate);

//counter equals
$count++;

//insert an image every 5 rows
if($count==5){
$count=0;
   echo "<table width='50%' style='border-bottom:1px solid #000000;'>";
echo "<tr>";
echo "<td>";
echo "<div id='page-wrap'>";
echo "<div class='discounted-item freeshipping'>";

echo "<a href='images/box1.png' rel='lightbox'><img src='images/box1.png' width='160px' height='200px' /></a>";


echo "<div class='reasonbar'><div class='prod-title' style='width: 70%;'>AN AD CAN GO HERE</div><div class='reason' style='width: 29%;'><b>Ad Company</b></div></div>";

echo "<div class='reasonbar'><div class='prod-title1' style='width: 70%;'>Description about the advert from a company</div><div class='reason1' style='width: 29%;'>Category: Advert</div></div>";

echo "<div class='reasonbar'><div class='prod-title2' style='width: 70%;'>HELLO, User</div><div class='reason2' style='width: 29%;'></div></div>";


echo "</td>";
echo "</tr>";
echo "</td>";
echo "</tr>";
echo "</table>";
}

echo "<table width='50%' style='border-bottom:1px solid #FFFFFF'>";
echo "<tr>";
echo "<td>";
echo "<div id='page-wrap'>";
echo "<div class='discounted-item freeshipping'>";

echo "<a href='./img/users/" . $row['category'] . "/" . $row['username'] . "/" . $row['filename'] . "' rel='lightbox'><img src=\"./img/users/" . $row['category'] . "/" . $row['username'] . "/" . $row['filename'] . "\" alt=\"\" width='80px' height='100px' /></a>";


    echo "<div class='expanderHead'>";

echo "<div class='reasonbar'><div class='prod-title'>" .$row['fname'] . "</div><div class='reason' style='width: 29%;'><b>". $row['firstname'] . " " . $row['surname'] ."</b></div></div>";


echo "<div id='expanderContent' style='display:none'><div class='reasonbar'><div class='prod-title1'>" . $row['lname'] . "</div><div class='reason1' style='width: 29%;'>Category:<br /> ". $row['category'] . "</div></div>";

    echo "<div class='reasonbar'><div class='prod-title2' style='width: 70%;'><form action='adclick.php' method='post'><input type='hidden' name='username' value='" . $row['username'] . "'/><input type='submit' name='submit' value='Reply To this ad'></form></div><div class='reason2' style='width: 29%;'></div></div></div>";


echo "<div class='reasonbar'><div class='prod-title2' style='width: 70%;'>Expires: $sDate</div><div class='reason2' style='width: 29%;'>Price: &pound;". $row['price'] . "</div></div>";



echo "</td>";
echo "</tr>";
echo "</td>";
echo "</tr>";
echo "</div>";
echo "</table>";




}


}

else
    echo "No results found for \"<b>$search</b>\"";


//disconnect
mysql_close();

?>
</div>  
</div> 
<div class="footer">
<p> <a href="">Private Policy</a> | <a href="">Terms and Conditions</a> | <a href="">FAQ</a>   </p>
</div> 
</body>
</html>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T07:51:18+00:00Added an answer on June 12, 2026 at 7:51 am

    Sample Code:

    $start is the starting number,$limit is the ending number (for one page).. $count is total number of records

    echo "<h5>Showing ".$start." to ".($start+$limit)." Records of ".$count." Records</h5>";
    if($start<=($count-$limit))
    {
        echo '<a style="float:right" href="'.$_SERVER['PHP_SELF'].'?start='.($start+$limit).'&limit='.$limit"><t1>Next</t1></a>';
    }
    
    
    $prev = $start-$limit;
    if ($prev >= 0)
    {
        echo '<a style="float:left" href="'.$_SERVER['PHP_SELF'].'?start='.$prev.'&limit='.$limit"><t2>Previous</t2></a>';
    }
    
    
    $i=0;
    $l=1;
    echo "<p align='center'>";
    for($i=0;$i < $count;$i=$i+$limit)
    {
        if($i <> $start)
        {
            echo "<a href='listing_test.php?start=$i&limit=$limit'><font face='Verdana' size='2'><b>&nbsp;$l&nbsp;</b></font></a> ";
        }
        else
        {
            echo "<font face='Verdana' size='4' color=#2E9AFE ><b>&nbsp;$l&nbsp;</b></font>";
        }        
    $l=$l+1;
    }
    echo "</p>";
    

    EDIT:

    $result = mysql_query("SELECT * FROM table_name LIMIT ".$start.",".$limit);
        $total=mysql_query("SELECT * FROM table_name");
        $count=mysql_num_rows($total);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have tried a few things to solve this problem but I can't seem
I have tried quite a few codes but none of them seem to work
I've seen a few similar posts and have tried out the answers given, but
Ok, stuck on another Python Question. I have tried this a few times, but
I noticed a few people have tried to do similar things that I am
I have tried this a few different ways and it always seems to fail.
So I am pretty new to JSP. I have tried this a few ways.
I have tried to figure this out and googled through a fair few stack
Since a few days I'm unable to start resque I have tried debugging this
I have been staring at this code for few hours, tried walkthrough,debugging with autos

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.