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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T18:47:16+00:00 2026-06-02T18:47:16+00:00

Let’s say I want to use the $wpdb class to retrieve image locations from

  • 0

Let’s say I want to use the $wpdb class to retrieve image locations from the database so I can then create a gallery of images. I have this code, but when I press ‘next’, the link doesn’t seem to go anywhere. Am I missing something?

<?php
global $wpdb;
$wpdb->show_errors();
$offset = 0;
if( isset($_GET['page']) && !empty($_GET['page']) ){
$offset =  ($_GET['page']-1) * 10; // (page 2 - 1)*10 = offset of 10
}
$pics = $wpdb->get_col("SELECT pic_thumb_url FROM wp3_bp_album 
WHERE owner_type = 'user' ORDER BY title DESC
LIMIT 10 OFFSET $offset"
);
//LIMIT shows 10 results per page
//OFFSET will 'skip' this number off results. On page 1 the offset is 0 on page 2 it is 10       (if 10 results per page)
foreach($pics as $pic) :
echo '<a href ="'. '#' .'" > <img src="' . $pic . '">' . '</a>';

endforeach; 


/*
pagination
*/
?>
<a href="/community/?page=<?php echo $_GET['page']-1 ?>">previous</a>
<a href="/community/?page=<?php echo $_GET['page']+1 ?>">next</a>

Can I implement pagination with this?

  • 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-02T18:47:17+00:00Added an answer on June 2, 2026 at 6:47 pm

    You can’t use the built-in pagination, but to use pagination use an OFFSET and a LIMIT in your query. So, make your own pagination:

    <?php
    $offset = 0;
    if(isset($_GET['page']) && !empty($_GET['page']) {
        $offset =  ($_GET['page']-1) * 10; // (page 2 - 1)*10 = offset of 10
    }
    $wpdb->get_col("SELECT pic_thumb_url FROM wp3_bp_album 
        WHERE owner_type = 'user' ORDER BY title DESC
        LIMIT 10 OFFSET $offset"
    );
    //LIMIT shows 10 results per page
    //OFFSET will 'skip' this number off results. On page 1 the offset is 0 on page 2 it is 10 (if 10 results per page)
    
    /*
    pagination
    */
    ?>
    <a href="/currentpage/?page=<?php echo $_GET['page']-1 ?>">previous</a>
    <a href="/currentpage/?page=<?php echo $_GET['page']+1 ?>">next</a>
    

    Not flawless, it doesn’t check if you are on the first or last page but at least the first check you have to build yourself.

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

Sidebar

Related Questions

Let's say I have an image called hello.png with dimensions 200x100 . I create
Let's say R is a mxn random matrix. How can generate R with each
Let's say I have the following models class Photo(models.Model): tags = models.ManyToManyField(Tag) class Tag(models.Model):
Let's say I dynamically create a timer like this: System.Timers.Timer expirationTimer = new Timer(expiration
Let's say the Activity I want to start is named OccupyThePieShop I was previously
Let's say on a page I have alot of this repeated: <div class=entry> <h4>Magic:</h4>
Let's say I can call a method like this: core::get() . What is the
Let's say there is a graph and some set of functions like: create-node ::
Let's say that I have a model that handles recipes, and I want to
Let's say i have a mysql database table 'article' with the following fields: id

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.