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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T22:39:39+00:00 2026-06-14T22:39:39+00:00

OK i have a basic php pagination script, which has a basic next and

  • 0

OK i have a basic php pagination script, which has a basic next and previous button. Now this works fine until i add a distinct clause. Please see code below.

$query = "SELECT COUNT(*) as num FROM $tableName WHERE engine='$type' AND manufacturer='$man' AND '$year' BETWEEN start_year AND end_year";
$total_pages = mysql_fetch_array(mysql_query($query));
$total_pages = $total_pages['num'];
echo "$total_pages";
$stages = 3;
$page = mysql_escape_string($_GET['page']);
if($page){
    $start = ($page - 1) * $limit; 
}else{
    $start = 0; 
    }   

// Get page data

$query1 = "SELECT Distinct model_group from $tableName WHERE engine='$type' AND manufacturer='$man' AND '$year' BETWEEN start_year AND end_year LIMIT $start, $limit";
$result = mysql_query($query1);

// Initial page num setup
if ($page == 0){$page = 1;}
$prev = $page - 1;  
$next = $page + 1;                          
$lastpage = ceil($total_pages/$limit);      
$LastPagem1 = $lastpage - 1;

Now if i change the query in query 1 to be

 $query = "SELECT * From

the code works fine, below is the code for my next and previous buttons.

Previous Button

  if ($page > 1){
        echo "<a href='$targetpage?page=$prev&type=$type&manufacturer=$manufacturer&year=$year'><div class='previous'><img src='images/PrevButton1.fw.png' width='108' height='58' style='border: none;'/></span></a>";
    }else{
        echo "<span class='disabled'><div class='previous'>Previous</span></span>"; }

Next Button


if ($page < $lastpage){ 
        echo "<a href='$targetpage?page=$next&type=$type&manufacturer=$manufacturer&year=$year'><div class='next'><img src='images/MoreButton1.fw.png' width='108' height='58' style='border: none;'/></span></a>";
    }else{
        echo "<span class='disabled'><div class='next'>More</span></span>";
    }

IS there anyway i can include the distinct value in to the count query? as i think it returns a different value to the second query.

  • 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-14T22:39:40+00:00Added an answer on June 14, 2026 at 10:39 pm

    i think you have to use a

    SELECT COUNT(DISTINCT *)
    

    in your first statement

    a better way in mysql is to fix your paging problem with the SQL_CALC_FOUND_ROWS option in your select:

    SELECT SQL_CALC_FOUND_ROWS * FROM mysql.user LIMIT 1
    

    your result will be 1 row… but with

    SELECT FOUND_ROWS();
    

    you become the count of your result without the limit!

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

Sidebar

Related Questions

Hello I have a basic php script which is used to display the price
I have a basic PHP script like this: <?php system(/bin/touch /root/testfile); When I run
I have a basic PHP mail() script which e-mails users the details of a
Hi i am a new programmer. i have a simple pagination which works fine
I have a basic PHP script. $hike_id = $_REQUEST['hike_id']; $height = $_REQUEST['height']; $width =
I have just a basic html form within index.php which contains two text fields:
I have a PHP script that does basic encryption of a string through the
We have a basic PHP script to extract the title and description for each
I have a basic php script that calls system(netstat -l) and the reads what
im new to php. I have a basic unlink php file which deletes a

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.