Jump to content

[solved] Select Numbers Per Page


[dx]

Recommended Posts

Hi,Lets say we have about 20 entries in table. 15 of them matches query example WHERE CATEGORY=1 LIMIT 10Now, we want to show 10 of them per page. If I set $page = $_GET['page']; and use ?page=1 I'll got first 10th entries.Then when I use ?page=2, I should get next five entries. But how to continue on 11th entry.What query should be used here?Note that in table we have more options where category is 2, 3, etc.Regards

Link to comment
Share on other sites

Just one more thing.If I have some entries which belongs to category 2, but somewhere between those which belongs to category 1. Now to execute them?Example: if 1, 2, 3, 5, 6 entries belongs to 1 and 4 belongs to 2. Now I want to make previous and next page.When I'm on page 5 and want to go previous (which should be 3), I get 5 becouse 4 belongs to category 2.I've tried to use LIMIT " . ($picture - 2) .", 1Regards

Link to comment
Share on other sites

Already used.

$prevoius = mysql_fetch_array(mysql_query("SELECT ID_PICTURE FROM $table_gallery_pic WHERE ID_CAT=$album AND approved=1 LIMIT 1"));$next = mysql_fetch_array(mysql_query("SELECT ID_PICTURE FROM $table_gallery_pic WHERE ID_CAT=$album AND approved=1 LIMIT $picture, 1"));$picture_album = mysql_fetch_array(mysql_query("SELECT date, description, height, width, filename, title FROM $table_gallery_pic WHERE ID_CAT=$album AND ID_PICTURE=$picture"));

Link to comment
Share on other sites

Well,I have tableID_PICTURE ID_CAT approved1 1 12 1 13 1 14 2 15 1 16 1 1Now, to get correctly $previous and $next pagesThese codes seems to not shows fine it.These are my codes now:$previous = mysql_fetch_array(mysql_query("SELECT ID_PICTURE FROM $table_gallery_pic WHERE ID_CAT=$album AND approved=1 LIMIT " . ($picture - 2) . ", 1"));$next = mysql_fetch_array(mysql_query("SELECT ID_PICTURE FROM $table_gallery_pic WHERE ID_CAT=$album AND approved=1 LIMIT $picture, 1"));$picture_album = mysql_fetch_array(mysql_query("SELECT date, description, height, width, filename, title FROM $table_gallery_pic WHERE ID_CAT=$album AND ID_PICTURE=$picture"));And now. I'm on picture 1, previous should be 0 or nothing and that's ok. Next is 2Page 2, previous 1, next 3Page 3, previous 2, next 5 (becouse 4 is category 2)Page 5, previous 5, next 7 (there's problem)Page 7, previous 7, next 9 (and so on, previous is same as picture, and next skips by 2)

Link to comment
Share on other sites

Don't use the ID_PICTURE, store some other reference to the page and just calculate what ID to actually show when the script runs.

Link to comment
Share on other sites

Every other column in table is some information about picture like title, height, width, description etc. nothing which I could use.And when I open some album which uses ID_CAT I got just pictures from that album, and that's OK. So there must be some solution.But thanks in any case :)

Link to comment
Share on other sites

Sorry, was in a bit of a rush earlier. What I was trying to say is that, instead of directly using the ID_PICTURE, you just say "this is page one", "this is page two" (in the querystring), and then use LIMIT to get whatever picture is at that point, regardless of its actual ID. For example

$p = (int) $_GET['page'];$previous = $p - 1;$next = $p + 1;$p--;$picture_album = mysql_fetch_array(mysql_query("SELECT date, description, height, width, filename, title FROM $table_gallery_pic WHERE ID_CAT=$album LIMIT $p, 1"));

So in this case, it doesn't matter that IDs are skipped because you aren't even using the IDs for identification.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...