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 7530599
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T04:57:18+00:00 2026-05-30T04:57:18+00:00

I hope that title makes sense…. Basically I created PHP script to take data

  • 0

I hope that title makes sense…. Basically I created PHP script to take data from a database and display in, I then wrote some code to use a drop down menu to order that data. That all worked ok until I tried to utilise some pagination. I can make the pagination work, and I can make the ordering work, but not at the same time! At the moment the code that I have will allow me to order the list and almost paginate it. There are 40 results and I want to display 10 at a time. When not using the ordering code I can paginate it perfectly but when I try to intergrate the two bits of code it will only display the first 10 results and not give me an option to go to the next page to see the rest! (please bear in mind that I only started learning 5 das ago so I am still getting to grips with it!

The code:

if (!isset($_GET[‘start’]))
{

$_GET[‘start’] = 0;
}

$per_page = 10;
$start = $_GET[‘start’];

if (!$start)
   $start = 0;



$sort = @$_POST['order'];  
if (!empty($sort)) {   
$get = mysql_query("SELECT bookname, bookauthor, bookpub, bookisbn
            FROM booktable
            ORDER BY ".mysql_real_escape_string($_POST['order'])." ASC
            LIMIT $start, $per_page");
}
 else { 
$get = mysql_query("SELECT bookname, bookauthor, bookpub, bookisbn 
                FROM booktable 
                ORDER BY bookname ASC
                LIMIT $start, $per_page"); 
}

$record_count = mysql_num_rows($get);


?>
<?php
if (isset($_GET['showerror']))
$errorcode = $_GET['showerror'];
else
$errorcode = 0;
?>

wont include all the html rubbish and the ordering menu!

<div id="mid">

<?php
echo "<table>";
echo "<tr>";
echo "<th>";

echo "</th>";
echo "<th>";
echo "Book Title";
echo "</th>";
echo "<th>";
echo "Book Author";
echo "</th>";
echo "<th>";
echo "Book Publisher";
echo "</th>";
echo "<th>";
echo "Book ISBN";
echo "</th>";
echo "<th>";

echo "</th>";
echo "</tr>";
while ($row = mysql_fetch_assoc($get))
{
 // get data
 $bookname = $row['bookname'];
 $bookauthor = $row['bookauthor'];
 $bookpub = $row['bookpub'];
 $bookisbn = $row['bookisbn'];



    echo "<tr>";
    echo "<td>";
    echo "<a href='addtolist.php?bookname=".$bookname."&bookauthor=".$bookauthor."&bookpub=".$bookpub."&bookisbn=".$bookisbn."'>Add to basket</a>";

    echo "</td>";

    echo "<td>";
    echo $bookname;
    echo "</td>";

    echo "<td>";
    echo $bookauthor;
    echo "</td>";

    echo "<td>";
    echo $bookpub;
    echo "</td>";

    echo "<td>";
    echo $bookisbn;
    echo "</td>";

    echo "</tr>";


}

echo "</table>";

$prev = $start - $per_page;
$next = $start + $per_page;

if (!($start<=0))
       echo "<a href='products.php?start=$prev'>Prev</a> ";

       //set variable for first page number
$i=1;

//show page numbers
for ($x = 0; $x < $record_count; $x = $x + $per_page)
{
 if ($start != $x)
    echo "<a class='pagin' href='products.php?start=$x'> $i </a>";
 else
    echo "<a class='pagin' href='products.php?start=$x'><b> $i </b></a>";
 $i++;
}

//show next button
if (!($start >= $record_count - $per_page))
       echo "<a class='pagin' href='products.php?start=$next'> Next </a>";
?>

Thank you so much for reading!

  • 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-05-30T04:57:20+00:00Added an answer on May 30, 2026 at 4:57 am

    Simpliest way just change $sort = @$_POST['order']; to $sort = @$_REQUEST['order']; and add to your pagination links &order=$order

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I hope the title makes sense. I have a set of items that I
I'm busy writing a PHP app that gets data from a database, but I
I hope this title makes sense - I need case-insensitive regex matching on BlackBerry
I hope the title of this question makes sense. What I want to know
I hope my title makes sense, but here is what I a trying to
I'm not sure if the title makes sense, but I hope you can understand
i hope that everyone here know the php 'variable variable' syntax: $color = 'red';
I downloaded these zip files from the link http://netbeans.org/downloads/zip.html with the hope that this
Not sure if that was the best Title in the world but I hope
Is there any way (utilizing Reflection I hope) that I can make an instantiated

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.