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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T15:04:32+00:00 2026-05-14T15:04:32+00:00

Hey, I want to add a button(link), that when clicked will filter the pagination

  • 0

Hey, I want to add a button(link), that when clicked will filter the pagination results.

I’m new to php (and programming in general) and would like to add a button like ‘Automotive’ and when clicked it updates the 2 mysql queries in my pagination script, seen here:

As you can see, the category automotive is hardcoded in, I want it to be dynamic, so when a link is clicked it places whatever the id or class is in the category part of the query.

1:

$record_count = mysql_num_rows(mysql_query("SELECT * FROM explore WHERE category='automotive'"));

2:

$get = mysql_query("SELECT * FROM explore WHERE category='automotive' LIMIT $start, $per_page");

This is the entire current php pagination script that I am using:

<?php

    //connecting to the database
    $error = "Could not connect to the database";
    mysql_connect('localhost','root','root') or die($error);
    mysql_select_db('ajax_demo') or die($error);

    //max displayed per page
    $per_page = 2;

    //get start variable
    $start = $_GET['start'];

    //count records
    $record_count = mysql_num_rows(mysql_query("SELECT * FROM explore WHERE category='automotive'"));

    //count max pages
    $max_pages = $record_count / $per_page; //may come out as decimal

    if (!$start)
       $start = 0;

    //display data
    $get = mysql_query("SELECT * FROM explore WHERE category='automotive' LIMIT $start, $per_page");
    while ($row = mysql_fetch_assoc($get))
    {
     // get data
     $name = $row['id'];
     $age = $row['site_name'];

     echo $name." (".$age.")<br />";

    }

    //setup prev and next variables
    $prev = $start - $per_page;
    $next = $start + $per_page;

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

    //show page numbers

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

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

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

    ?>
  • 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-14T15:04:32+00:00Added an answer on May 14, 2026 at 3:04 pm

    Example with 2 links/categories:

    <a href='script.php?category=automotive'>automotive</a> <a href='script.php?category=sports'>sports</a>
    

    Inside script.php:

    $category = mysql_real_escape_string($_GET['category']);
    $record_count = mysql_num_rows(mysql_query("SELECT * FROM explore WHERE category='$category'"));
    ...
    $get = mysql_query("SELECT * FROM explore WHERE category='$category' LIMIT $start, $per_page");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hey i want to use php to redirect a user to a url depending
Hey so what I want to do is snag the content for the first
Hey guys i wrote a quick test. I want delete to call deleteMe which
hey, what do i have to write, if i want date&time which updates itself?
Hey, I've been developing an application in the windows console with Java, and want
I have a string of test like this: <customtag>hey</customtag> I want to use a
Hey guys, quick question, I have an id that is applied multiple times on
I have an image that is animating, until you press the button that says
Hey i want to create a list like this. The pic below isnt my
Hey guys. I have the following situation. I want to use a TypeDescriptor to

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.