Complicated pagination logic problem

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
'll try to explain this as clearly as possible, sorry if it's unclear.

You have in your directory /foo 42 images

You have in your database metadata for 30 out of those 42 images

You have to display all 42 images in the /foo directory whether they
have database metadata or not.

If any of the 42 images have metadata, you must display the metadata,
else, you don't.

With me so far? Good, it gets wild from here.

You have a requirement for pagination.

Your pagination limit is to only show 20 images at a time.

The only way I know how to do this is to get all of the images out of
the filesystem pertaining to /foo, all of the metadata out of the
database pertaining to /foo, and logically combine them (using
array_merge()) into a single resultset and display, metadata or not.

However, to paginate to the next page, you'll have to have had stuffed
THE ENTIRE RESULTSET into a $_SESSION variable and splice that.

That of course is not good. But what on earth else do I do? If I am not
to use $_SESSION, how would I paginate such an exotic resultset?


Re: Complicated pagination logic problem

comp.lang.php wrote:
Quoted text here. Click to load it
Just put a hidden variable with the next picture to start with on your  
form. Then after merging the arrays (it might be better to start with an  
array of filenames not the pictures themselves) use the hidden  
variable's value to select which part of the array to display.

Re: Complicated pagination logic problem

Bob Stearns wrote:
Quoted text here. Click to load it

I'm sorry I honestly can't follow anything you suggested.  I would have
an array of filenames already.

I wound up chucking the entire idea and just merging together an array
of every filename in the filesystem under the album (directory) with a
database table query of all files with metadata where "image_path" is
the name of the album (directory); placing the merged data into a
temporary table and then retrieving that data at one shot using ORDER


Re: Complicated pagination logic problem

comp.lang.php wrote:
Quoted text here. Click to load it

There is no reason to stuff the whole array into the session.

This is no different than any other pagination implementation except
that the data is the combination of two different data sources (but
that fact does not change the difficulty at all).  Treat this exactly
as if you were just paging records in a database:
-On each page, limit your output to X elements
-On the link to the 'next' page, pass along an argument which contains
the id (in this case, either the filename or the index of the array
element) with which to begin displaying items on the following page.
-Then, on the next page load, regenerate your array and begin
displaying from the provided id value.

When you're paging records from a database you don't store the entire
resultset in the session, so why would you do any different here?

Re: Complicated pagination logic problem wrote:
Quoted text here. Click to load it

Because your approach would only optimally work if:

1) Every single image had metadata
2) Or not every image had metadata but there is no other sorting taking
place except for default sorting by image name

Because the moment I try to sort by a field other than image name, like
"image_location_country", the metadata fields should be first followed
by the non-metadata array, and with pagination, you are certain to lose
an image or two in your display because of that, and I honestly cannot
fathom a way to prevent that from happening.

I could only think of two solutions:

1) You stuff everything into $_SESSION and pull from there, sorted,
paginated and all
2) You constantly pull ALL images from /your_directory and ALL images
from the database where image_path LIKE '/your_directory/%' and combine
them into a temporary table, and from there, sort, paginate and voila!


Site Timeline