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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T06:51:27+00:00 2026-05-23T06:51:27+00:00

*EDIT*** I’ve made great progress by combining the main query that pulls the airwaves

  • 0

*EDIT***

I’ve made great progress by combining the main query that pulls the airwaves with some variables from the pagination query and have finally gotten the pagination to work. The only problem now is that the first page is blank and page two is correct starting with result 41-80

Here is the query that limits and pulls the airwaves

        $rowsperpage = 40;
        $currentpage = (int) $_GET['currentpage'];
        $offset = ($currentpage - 1) * $rowsperpage;
        $query = "SELECT * FROM `CysticAirwaves` WHERE `FromUserID` = `ToUserID` AND `status` = 'active' ORDER BY `date` DESC, `time` DESC LIMIT $offset, $rowsperpage" ;
        $request = mysql_query($query,$connection);
        $counter = 0;
        while($result = mysql_fetch_array($request)) {

and here is the pagination code:

$query = "SELECT COUNT(*) FROM `CysticAirwaves`";
                        $result = mysql_query($query, $connection) or trigger_error("SQL", E_USER_ERROR);
                        $r = mysql_fetch_row($result);
                        $numrows = $r[0];

                        // number of rows to show per page
                        $rowsperpage = 40;
                        // find out total pages
                        $totalpages = ceil($numrows / $rowsperpage);

                        // get the current page or set a default
                        if (isset($_GET['currentpage']) && is_numeric($_GET['currentpage'])) {
                           // cast var as int
                           $currentpage = (int) $_GET['currentpage'];
                        } else {
                           // default page num
                           $currentpage = 1;
                        } // end if

                        // if current page is greater than total pages...
                        if ($currentpage > $totalpages) {
                           // set current page to last page
                           $currentpage = $totalpages;
                        } // end if
                        // if current page is less than first page...
                        if ($currentpage < 1) {
                           // set current page to first page
                           $currentpage = 1;
                        } // end if

                        // the offset of the list, based on current page 
                        $offset = ($currentpage - 1) * $rowsperpage;

                        // get the info from the db 
                        $query2 = "SELECT `id` FROM `CysticAirwaves` LIMIT $offset, $rowsperpage";
                        $result = mysql_query($query2, $connection) or trigger_error("SQL", E_USER_ERROR);

                        // while there are rows to be fetched...
                        while ($list = mysql_fetch_assoc($result)) {
                           // echo data
                           echo $list['id'] . " : " . $list['number'] . "<br />";
                        } // end while

                        /******  build the pagination links ******/
                        // range of num links to show
                        $range = 3;

                        // if not on page 1, don't show back links
                        if ($currentpage > 1) {
                           // show << link to go back to page 1
                           echo " <a href='http://www.cysticlife.org/Airwave_build.php?currentpage=1'><<</a> ";
                           // get previous page num
                           $prevpage = $currentpage - 1;
                           // show < link to go back to 1 page
                           echo " <a href='http://www.cysticlife.org/Airwave_build.php?currentpage=$prevpage'><</a> ";
                        } // end if 

                        // loop to show links to range of pages around current page
                        for ($x = ($currentpage - $range); $x < (($currentpage + $range) + 1); $x++) {
                           // if it's a valid page number...
                           if (($x > 0) && ($x <= $totalpages)) {
                              // if we're on current page...
                              if ($x == $currentpage) {
                                 // 'highlight' it but don't make a link
                                 echo " [<b>$x</b>] ";
                              // if not current page...
                              } else {
                                 // make it a link
                                 echo " <a href='http://www.cysticlife.org/Airwave_build.php?currentpage=$x'>$x</a> ";
                              } // end else
                           } // end if 
                        } // end for

                        // if not on last page, show forward and last page links        
                        if ($currentpage != $totalpages) {
                           // get next page
                           $nextpage = $currentpage + 1;
                            // echo forward link for next page 
                           echo " <a href='http://www.cysticlife.org/Airwave_build.php?currentpage=$nextpage'>></a> ";
                           // echo forward link for lastpage
                           echo " <a href='http://www.cysticlife.org/Airwave_build.php?currentpage=$totalpages'>>></a> ";
                        } // end if
                        /****** end build pagination links ******/
                        ?>

So long story short, I just am not able to pull the first 40 results but after that its fine

  • 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-23T06:51:27+00:00Added an answer on May 23, 2026 at 6:51 am

    This is a better way to go about pagination:

    SELECT SQL_CALC_FOUND_ROWS id FROM `CysticAirwaves` LIMIT $offset, $rowsperpage
    

    Select the data you want to display using the example query above which will return the same result as your query2

    Then execute another SQL query:

    SELECT FOUND_ROWS()
    

    This will return the number of rows found without using a limit. See more here:

    http://dev.mysql.com/doc/refman/5.0/en/limit-optimization.html

    This would be the fastest way to manage pagination.

    You would then loop through the results of your first query and display then. All you need to keep track of is what page you are on, and how many rows to show per page.

    If you page number * $rowsperpage > the result of the second select (FOUND_ROWS) then you do not need to calculate or show the ‘next’ pages options/links.

    For ‘next’ pages, loop 3 times incrementing the page number or next page * $rowsperpage > total rows.

    For ‘previous’ pages, loop 3 times decrementing the page number or previous page = 1 (break out of loop in this case).

    That should do the trick.

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

Sidebar

Related Questions

Edit: From another question I provided an answer that has links to a lot
EDIT: Learned that Webmethods actually uses NLST, not LIST, if that matters Our business
Edit: This was accidentally posted twice. Original: VB.NET Importing Classes I've seen some code
Edit : Note that my final purpose here is not having the class working,
Edit: This is technically a 2 part question. I've chosen the best answer that
(EDIT: I've edited my question to make it simpler, sorry if some answers are
EDIT: This is with Rails 2.3.5 For some reason, when I try to associate
EDIT: Please note that this question is OUTDATED; RVM got way easier to use
EDIT I added in some error handling to my .vbs file and it is
EDIT: This question was exceptionally dumb and made me look like a script kiddie,

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.