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

  • Home
  • SEARCH
  • 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 7656751
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T12:50:52+00:00 2026-05-31T12:50:52+00:00

Ok, I’ll paste my code here, it goes like if a person selects a

  • 0

Ok, I’ll paste my code here, it goes like if a person selects a category and then he lands to another page, now here the problem is because mysql_fetch_rows selects all the rows of all categories, so if there are 10 entries, 5 in each category and if i set to show 1 post per each page instead of showing 5 pages it shows 10 pages but after page 5 i get a php error. thank you n here’s my code

$pagination_shoot = "SELECT id, po_title, po_category FROM tbl_posts WHERE po_category = '{$category}'";

$page_dump = mysql_query($pagination_shoot, $db_connect);

$no_rows = mysql_fetch_row($page_dump);

$numrows = $no_rows[0];

$rows_per_page = 1;

$lastpage = ceil($numrows/$rows_per_page);

$page = (int)$page;

if ($page > $lastpage) {
$page = $lastpage;
} // if

if ($page < 1) {
$page = 1;
} // if

$limit = 'LIMIT ' .($page - 1) * $rows_per_page .',' .$rows_per_page;

//Run Post Query
$data_posts = "SELECT id, po_title, po_category FROM tbl_posts WHERE po_category = '{$category}' {$limit}"; //Post Query

$fetch_data_posts = mysql_query($data_posts, $db_connect);

while ($list_posts = mysql_fetch_array($fetch_data_posts))
  • 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-31T12:50:53+00:00Added an answer on May 31, 2026 at 12:50 pm

    Reading between the lines, I think what you are trying to do is fetch the results for a specific page from that database while knowing how many results there are in total, so you can work out how many pages there will be. Here is the right way to do that using SQL_CALC_FOUND_ROWS:

    // Populate these variables however you see fit (eg through $_GET)
    $rows_per_page = 1;
    $current_page = 1;
    
    // -----------
    
    // Make sure the page number is >= 1
    $current_page = (int) $current_page;
    if ($current_page < 1) $current_page = 1;
    
    // Calculate values for LIMIT clause
    $limitQty = (int) $rows_per_page;
    $limitBase = ($current_page - 1) * $limitQty;
    
    
    // Run the query
    $query = "
      SELECT SQL_CALC_FOUND_ROWS
        `id`, `po_title`, `po_category`
      FROM `tbl_posts`
      WHERE `po_category` = '".mysql_real_escape_string($category, $db_connect)."'
      LIMIT $limitBase, $limitQty
    ";
    $result = mysql_query($query, $db_connect);
    
    // Store the results in an array and free the MySQL resource
    $data_posts = array();
    while ($row = mysql_fetch_array($result)) {
      $data_posts[] = $row;
    }
    mysql_free_result($result);
    
    // Get the total number of rows
    $query = "
      SELECT FOUND_ROWS()
    ";
    $result = mysql_query($query, $db_connect);
    $numrows = mysql_fetch_row($result);
    $total_rows = $numrows[0];
    mysql_free_result($result);
    
    // Calculate the total number of pages
    $total_pages = ceil($total_rows / $rows_per_page);
    
    if ($current_page > $total_pages) {
      // Handle a request that asked for a page which is greater than the total number of pages
      // You could display an error message, redirect to a page within range, or run another query
      // to fetch the rows for the last page.
    }
    
    // Now you can loop the data results and do whatever you want with them
    foreach ($data_posts as $list_posts) {
      // ...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a jquery bug and I've been looking for hours now, I can't
Basically, what I'm trying to create is a page of div tags, each has
this is what i have right now Drawing an RSS feed into the php,
I've got a string that has curly quotes in it. I'd like to replace

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.