Her
Getting back on track, we will now display the pages in between (not previous or next). To do so, we will use a for loop. View the code below:
This is a basic for loop structure, where it will loop until it is less than or equal to the value of $total_pages. Inside the for loop, we set a condition that if $a equals the current page, to just echo that value, not linked (because we're already on that page). If not, echo the rest of the pages, linked.
Displaying the next page link is identical to displaying the previous page link. Your code should look a bit like this:
Set the value of next page in the $next_page variable by taking the value of the current page ($page) and adding 1. Now, we have the condition that will be executed and display the back link only if $next_page is less than or equal to the value of $total_pages. That is all for displaying the paginated links.
I would like to bring important information to your attention. If your category names contain spaces, like, "visual basic" when you try to use that in your link, it will not link properly. Because, it will only read until the space is encountered, and then stops. Your link would read, "visual" instead. Therefore, we will use the function, urlencode(); to replace those spaces so that the browser can interpret them. See the code below,
Simple as that. Now, if $cat was, "visual basic" it is now "visual+basic" and the links will be valid, and browser friendly. Just be sure to place this line of code before the code where you begin to display the links.
Now that we have covered though the entire script, piece by piece- follow the link below to view the entire code:
Also, keep in mind that if you just copy and paste this script, it will _not_ work. You need to edit the script to meet your needs, like the table name, link paths, database connection, -pretty much everything. But I put in comments where changes need made.
Working Example
Until next time, happy coding~