Dynadot — .com Registration $8.99

Help with Pagination

Spaceship Spaceship
Watch

-LB-

Established Member
Impact
19
Well, I need some help on getting page numbering on my website, http://soadtalk.com without using a database.

A you can see the site has a lot of content on the main page and I want to have page numbering at the bottom so it's like:

« 1 2 3 4 5...25 »

If you could post some sort of code or direct me into a website which can tell me how to do this in easy steps (i'm seriously no PHP expert) then that would be awesome.

Thanks,
Lewis

Edit:// I'm manually adding news articles to main.php which index.php is including but the content just builds and builds and builds and i wanna neaten it up nicely. any help is appreciated. :)
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
AfternicAfternic
Hm, it depends how easily you want to be able to maintain the "pages" of content.

Write a page of content, surround it with a PHP statement that says something like "if p=1, then show this, else if p=2, show this, else ... etc." ...

So you could do it with IF statements, or you could get a little fancier and do a loop (store each HTML post in an array element)... then treat it like a database query.

If you want to get more detailed, just ask.
 
0
•••
One of the more challenging tasks you'll face as a PHP programmer. You'll find great pagination examples and then you'll find more complicated and challenging.

Usually the more challenging will give you much better looking pagnation results:

[Prev 1 20 30 50 100 250 Next]

vs

[1 2 3 4 5 6 7 8 9 10 11 12 13 14 ..... 250]

So I mean not only will you need to handle the SQL portion (to limit each result based on the current page (ie: if you allow 10 results per page, and your viewing page 3 that means you need to serve results 30 to 40)..

Then once you determine that you're going to need to group some results so your pagnation is not going 1 2 3 4 5 .. instead it's 1 5 20 50 100 250... depending on how many pages you'll be spanning the 10 results per page on.

I know this isn't much in terms of helping you with code, but you need to know that this is not as simple as it appears. There is much going on to get "great" looking pagniation results.. I would search the web for some examples.. but remember that the page grouping is a great feature just in case your db has more than 1,000 results.

But one thing I do know, once you figure out what works for you, you'll begin refining it to your exact look and feel. What is more, you'll be able to reuse this code for other projects you may have.

Good luck! :D

I'm very sorry about my response. I just realized that you mentioned you are not using a db.
 
0
•••
Yeah, it's not too bad if you store your HTML content as array elements. You know an array is a container: much like a big shipping box with a bunch of little boxes inside it, each one numbered, the numbering starting at 0.

PHP:
$myarray[0] = "woohoo";
$myarray[1] = "something else";
$myarray[2] = "this would be another individual post, see?";

If you don't mind having one file for each post you make then do this:

- Create a subdirectory, call it "/posts" (or whatever you want).

- Use PHP to read all files in that directory. You can do this by date or by file name, if you named your files things like 1.html, 2.html... if you want the most recent on top, you'll need to sort descending - easy to do. Either way, there are options here.

- Read the contents of each file and put the contents into an array.


See, as you read from a database, all the results are stored in an array anyway (generally speaking). So this now can work just like a database query:

- Run a loop on the array (a for loop might be best), depending on what page you're currently on, how many per page, etc.

That should be pretty flexible.

Once your code is done, all you have to do is make a .html file in the /posts directory and make its name (a number) 1 more than your post before. See?
 
0
•••
Hey,

I'm now using a CMS news system (Fusion News) and have tweaked it to my liking but I shall be taking all of the comments you have have given in so I can apply them to my other sites.

Thanks a lot!
 
0
•••
Dynadot — .com Registration $8.99Dynadot — .com Registration $8.99

We're social

Unstoppable Domains
Domain Recover
DomainEasy — Live Options
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back