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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T08:56:18+00:00 2026-06-07T08:56:18+00:00

I have a gallery page I am working on and cannot seem to get

  • 0

I have a gallery page I am working on and cannot seem to get the next set of images to load correctly by using GET parameter page=2.

I am using a table, with 6 images, and next and previous buttons.
When i click Next from page1 however, it loads images 8 to 13, instead of the agreed-upon 7 to 12.

The code is here:

<?php 
echo "<table width=\"490\" border=\"1\" align=\"center\">";
if(isset($_GET['page'])){
//Read Page, Set Start image, End image
$cur_page=abs($_GET['page']);
//if the page is page1, then set the defaults
if($cur_page==1){
    $prev_page=0;
    $next_page=2;
    $start_img=0;
    $last_img=6;
    }
    //if the page is not page1, calculate the defaults
    else{
        $prev_page=$cur_page-1;
        $next_page=$cur_page+1;
        $start_img=(($cur_page-1)*6)+1;
        $last_img=$start_img+5;
        }
}else{
//Page=1 start image=1 end image=6
$cur_page=0;
$prev_page=1;
$next_page=2;
$start_img=0;
$last_img=6;
}
//Do the sql query for the images
$sql="SELECT * FROM images LIMIT $start_img, 6";
$result = mysql_query($sql, $conn) or die(mysql_error());
//Set a counter variable to iterate the image display
$count=0;

//Begin the table that displays the images.
while ($newArray = mysql_fetch_array($result)) {
$count++;
//Print the odd-numbered column first
if($count%2==1){
    echo "<tr><td width=\"50%\"><a href=\"$newArray[Pic_Address]\">$newArray[Pic_Address]</a></td>";
//Print the even-numbered column next
}else{
    echo "<td width=\"50%\"><a href=\"$newArray[Pic_Address]\">$newArray[Pic_Address]</a></td></tr>";
}
}
//print the next and previous Links
echo "<tr>";
if($prev_page==0){echo "<td align=\"center\">Prev</td>";}else{echo "<td align=\"center\"><a href=\"index.php?page=$prev_page\">Prev</a></td>";};
echo "<td align=\"center\"><a href=\"index.php?page=$next_page\">Next</a></td>";

echo "</tr>
</table>";

//Printscreen to test the page-load variables.

echo "  <p align=\"center\">
    current page=$cur_page <br>
    prev_page=$prev_page <br>
    next_page=$next_page <br>
    start_img=$start_img <br>
    last_img=$last_img <br>
    </p>
    ";
?>
  • 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-06-07T08:56:21+00:00Added an answer on June 7, 2026 at 8:56 am

    The problem is in these lines:

    $start_img=0;
    $last_img=6;
    

    &

    $start_img=(($cur_page-1)*6)+1;
    $last_img=$start_img+5;
    

    These lines, when page=1, will load images from ID 0 to ID 6, total 7 images and when page=2, the code will result in $statr_img = ((2-1)*6)+1 = 7 and ID 7 actually will be 8th image, because we are counting from 0. Same, $last_img = 7+5 = 12 and again, ID 12 is the 13th image.

    UPDATE:

    Here is the updated complete code. No need for an if/else . Ofcourse you need to sanitize $_GET.

    $cur_page = $_GET["page"];
    $prev_page=$cur_page-1;
    $next_page=$cur_page+1;
    $start_img=(($cur_page-1)*6);
    $last_img=$start_img+5;
    

    Results for Page =1,2,3 ($cur_page is 1 or 2 or 3) from above code:
    Page=1, Results:

    $prev_page = 1-0 = 0    
    $next _page = 1+1 = 2
    $start_img = ((1-1)*6) = 0*6 = 0
    $last_img = 0+5 = 5
    

    Page=2, Results:

    $prev_page = 2-0 = 1
    $next _page = 2+1 = 3
    $start_img = ((2-1)*6) = 1*6 = 6
    $last_img = 6+5 = 11
    

    Page=3, Results:

    $prev_page = 3-0 = 2
    $next _page = 3+1 = 4
    $start_img = ((3-1)*6) = 2*6 = 12
    $last_img = 12+5 = 17
    

    Also, use of <table> for layouts is strongly discouraged. Please look into CSS & DIVs. Look into this code for implying same design in CSS.

    //continued from above $var calculating code + your MySql code
    
    //Set a counter variable to iterate the image display
    $count=0;
    
    while ($newArray = mysql_fetch_array($result)) {
        $count++;
        echo "<div id=\"table\">\r\n";
        // Print the odd-numbered column first
        // if ID is 0,2,4 then Images are 1,3,5 OR odd
        if($count%2==0){
            echo "<div id=\"row\">\r\n<div class=\"cell\">\r\n<a href=\"$newArray[Pic_Address]\">$newArray[Pic_Address]</a></div><!--//cell-->\r\n";
        } else { // IDs are 1,3,5 OR Images are 2,4,6 OR even
            echo "<div class=\"cell\"\r\n><a href=\"$newArray[Pic_Address]\">$newArray[Pic_Address]</a></div><!--//cell-->\r\n</div><!--//row-->\r\n";
        } //else ends
     // while ends
    
    //print the next and previous Links
    echo "<div id=\"links\">\r\n";
    
    if($prev_page != 0)
        echo "<a href=\"index.php?page=$prev_page\">";
    echo "Prev"
    if($prev_page != 0)
            echo "</a>\r\n";
    echo "<a href=\"index.php?page=".$next_page."\">Next</a>\r\n";
    echo "</div><!--//links-->\r\n"
    
    echo "</div><!--//table-->\r\n"
    

    So, now your page structure is like:

    +----------------table-----------------+
    | +---------------row----------------+ |
    | | +----cell------+------cell-----+ | |
    | | |    img       |     img       | | |
    | | +--------------+---------------+ | |
    | +---------------row----------------+ |
    | | +----cell------+------cell-----+ | |
    | | |    img       |     img       | | |
    | | +--------------+---------------+ | |
    | +---------------row----------------+ |
    | | +----cell------+------cell-----+ | |
    | | |    img       |     img       | | |
    | | +--------------+---------------+ | |
    | +----------------------------------+ |
    | +--------------links---------------+ |
    | |    Prev                Next      | |
    | +----------------------------------+ |
    +--------------------------------------+
    

    Of course you need to check out magical Float property of CSS for each Div. I would leave that to you (Google Css Float).

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

Sidebar

Related Questions

I have a gallery page with many images that I would like to load
I have a website with a gallery set of pictures I'm working on. The
I'm using Facebook Likes in my site. I have a gallery page which shows
I have a photo gallery web page where a single <img src="XXX" /> element's
I have a page with photo gallery http://dev.dolina-imeniy.ru/fotogalereya/kp_usadba_tishnevo/ I use this to bind click
I have a gallery of images on my website. Under each one, I'd like
I'm working on a video gallery page where there are 6 thumbnails and the
I have the following event: Ext.onReady(function() { Ext.select('.gallery-item img').on('click', function(e) { Ext.select('.gallery-item').removeClass('gallery-item-selected'); Ext.get(e.target).parent().addClass('gallery-item-selected'); });
I have developed a Wordpress site that loads pages dynamically using the .load function.
I have an image gallery where the image and the previous/next links under the

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.