Jump to content
Sign in to follow this  
Dubird

another php/mysql question

Recommended Posts

Ok, here's the problem. On my graphics site, I have a TON of different things. I want to be able to display say 5 of them, but on the bottom, I want to generate a page number list (like page 1 2 3 with links). I can't seem to word that question in a way that I can find it through searching, so I thought I'd ask here. I've seen it before and it was pretty easy, but now I can't find it. ^_^;;


Yesterday was the deadline for all complaints!

acsig2016.jpg

Share this post


Link to post
Share on other sites


Ok, here's the problem. On my graphics site, I have a TON of different things. I want to be able to display say 5 of them, but on the bottom, I want to generate a page number list (like page 1 2 3 with links). I can't seem to word that question in a way that I can find it through searching, so I thought I'd ask here. I've seen it before and it was pretty easy, but now I can't find it. ^_^;;

If the images have links in a database then use the limit option in your SQL. Your links at the bottom of the page pass the page number via a form or links with hard-coded $_GET parameters.

select * from `table` where some_condition order by some_variable desc limit page_number*limit, limit

select * from `table` where some_condition order by some_variable desc limit 25, 5


Understand this lad, fate is a fickle lady. Work with the hand you're dealt and you may just be able to run your flag up the pole. Don't, and well, you may just find your mast cut down.

Share this post


Link to post
Share on other sites

Count the number of images via sql query or by reading the directory. Divide the count by the number of images per page. Now that you know how many pages there are, create a link for each page passing the page number selected. Select the number of images from your limit starting at the page number times the limit using the limit sql example, or start a for loop with a starting position of the page number times the limit. Display your images.

select count([I]some_variable[/I]) as [I]total_images[/I] from `[I]table[/I]` where [I]some_condition[/I]

Use the previous limit sql example to display your images.

If you are reading the directory directly then use the readdir function to read each filename into an array.

http://us3.php.net/manual/en/function.readdir.php

Use the opendir function to allow you to read the directory.

for ($i = $page_number * $limit; $i < $page_number * $limit + $limit; $i++)
{
  // Create array of displayed images with the readdir function.
}

Create the page number links in a list and style with CSS or print one after the other in a <div> or <p>.

print "&lt;ol&gt;";

for ($i = 0; $i &lt; $total_images; $i++)
{
    print "&lt;li&gt;&lt;a href=\"some_page.php?page_number=" . $i . "\"&gt;" . $i . "&lt;/a&gt;&lt;/li&gt;";
}

print "&lt;/ol&gt;";


Understand this lad, fate is a fickle lady. Work with the hand you're dealt and you may just be able to run your flag up the pole. Don't, and well, you may just find your mast cut down.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...