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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T02:58:17+00:00 2026-05-24T02:58:17+00:00

I have this script below which i found on SO to generate pagination and

  • 0

I have this script below which i found on SO to generate pagination and broadly speaking, its working great, however because its a cut and paste job from me, i don’t understand how to actually generate the links which are echoed in the script with the variable $pagination.

What it echos is:

1< a href="index.php?page=2">2< a href="index.php?page=3">3< a hr_ef="?page=2"> Next 

None of which are working (clickable) links, and i also want to be able to style them so would rather output them in HTML, rather than a php echo, something like:

<p><?php 1< a href="index.php?page=2">2< a href="index.php?page=3">3< a hr_ef="?page=2"> Next ?> </p>

Below is the script i’m using:

<?php
/* Set current, prev and next page */
$page = (!isset($_GET['page']))? 1 : $_GET['page']; 
$prev = ($page - 1);
$next = ($page + 1);

/* Max results per page */
$max_results = 10;

/* Calculate the offset */
$from = (($page * $max_results) - $max_results);

/* Query the db for total results.*/
$result = mysql_query("...");
$total_results = mysql_num_rows($result);

$total_pages = ceil($total_results / $max_results);

$pagination = '';

/* Create a PREV link if there is one */
if($page > 1)
{
$pagination .= '< a href="?page='.$prev.'">Previous</a> ';
}

/* Loop through the total pages */
for($i = 1; $i <= $total_pages; $i++)
{
if(($page) == $i)
{
    $pagination .= $i;
}
else
{
    $pagination .= '< a href="index.php?page='.$i.'">'.$i.'</a>';
}
}

/* Print NEXT link if there is one */
if($page < $total_pages)
{
$pagination .= '< a hr_ef="?page='.$next.'"> Next</a>';
}

/* Below is how you query the db for ONLY the results for the current page */
$query ="SELECT * FROM ... LIMIT $from, $max_results";

$result=mysql_query($query) or die(mysql_error());
$rsjobinfo=mysql_fetch_assoc($result);

do {?>

<div>
[Individual Row Output]
</div>
<?php } while ($rsjobinfo=mysql_fetch_assoc($result));

echo $pagination;
?> 

Can someone help? I imagine its a small fix but as always, would appreciate a kick in the right direction.

Thanks
Dan

  • 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-24T02:58:19+00:00Added an answer on May 24, 2026 at 2:58 am

    Maybe it’s just an editing error, but in your output the <a>-tags don’t seem to be closed again. Also, there should be no space like < a> at the beginning of the tag. And < a hr_ef= ... is obviously wrong.

    In order to style them, you can add a class attribute to the tags while building the string and do the style-stuff in css.

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

Sidebar

Related Questions

I have this script which basically toggles a bgColor class on and off so
I have this script to generate an XML file for an RSS feed. Works
I have this script at the moment, which changes an image when a thumbnail
I've an annoying ASP.NET problem: I have a Perl script (see below), which gets
I found this script on about.com which I'm trying to learn from on how
I found this script on about.com which I'm trying to learn from on how
I have this sample below: <asp:Content ID=Content1 ContentPlaceHolderID=head runat=Server> <script type=text/javascript> function test(){ if
I have the script below which works well, i.e. it generates a chart on
I have this script: select name,create_date,modify_date from sys.procedures order by modify_date desc I can
i have this script $content = string if(!isset($_GET['page'])){ $page = 1; } else{ $page

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.