user3962336
user3962336

Reputation:

Paginating images from Flickr

I am trying to retrieve flickr images and show in my web page. Following articles I can show the images in my webpage. Now the problem is all the images are show in the first image- How I can do page paggination in php. I want to show only 6 images and rest are onsubsequently pages.

Code issue

$search = 'http://flickr.com/services/rest/?method=flickr.photos.search&api_key=' . $this->apikey . '&text=' . urlencode($query) . '&per_page=50&format=php_serial';
$result = file_get_contents($search);
$result_arr = unserialize($result);

In the above code I can get the all the images. What I need to do for paggination. Thank you for suggestion in advance.

Upvotes: 1

Views: 68

Answers (1)

TunaMaxx
TunaMaxx

Reputation: 1769

Looking at the Flickr API docs, there is a page argument you can pass along with the per_page that you are already providing.

per_page (Optional) - Number of photos to return per page. If this argument is omitted, it defaults to 100. The maximum allowed value is 500.

page (Optional) - The page of results to return. If this argument is omitted, it defaults to 1.

So I would try altering the &per_page=50 to be &per_page=6 and adding an incrementable page argument:

$page = (int) $page // However you want to pass / generate this
$search = 'http://flickr.com/services/rest/?method=flickr.photos.search&api_key=' . $this->apikey . '&text=' . urlencode($query) . '&per_page=6&page=' . $page . '&format=php_serial';

Upvotes: 1

Related Questions