SitePoint Sponsor |
|
User Tag List
Results 1 to 7 of 7
Thread: Select a row and rows around it
-
Nov 27, 2009, 15:28 #1
- Join Date
- Feb 2008
- Location
- end($world)
- Posts
- 834
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Select a row and rows around it
I'm developing an image gallery and on a page I want to show a single image and bellow it a thumbnails of 10 other images from the same gallery. The photo I am viewing should be in the middle of these thumbnails.
For example, there are 20 images in the gallery with ids:
Code:1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20
Code:7, 8, 9, 10, 11, 12, 13, 14, 15, 16
Code:10, 11, 12, 13, 14, 15, 16, 17, 18, 19
Code:2, 9, 15, 17, 26, 27, 28, 34 etc
-
Nov 27, 2009, 16:22 #2
This will give you max 10 images. If there are no 4 images before the current image, or 5 image after it, then the number of images returned will be less.
Guido - Community Team Leader
The Votes Are In: The Winners of the 2013 Community Awards are...
Blog - Free Flash Slideshow Widget
-
Nov 28, 2009, 02:58 #3
- Join Date
- Sep 2005
- Posts
- 335
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Alternatively, you can select 10 images before and 10 images after and then use PHP to determine the actual size of the two arrays returned if you need to display a full 10 additional images.
PHP Shopping Cart Software Easy Ecommerce Shopping Cart Script.
PHP Super Cart is 100% template driven.
-
Nov 28, 2009, 13:47 #4
- Join Date
- Feb 2008
- Location
- end($world)
- Posts
- 834
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
-
Nov 28, 2009, 14:04 #5
- Join Date
- Feb 2008
- Location
- end($world)
- Posts
- 834
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Here's the query:
Code:SELECT A.* FROM (SELECT * FROM media WHERE id < 7 ORDER BY id DESC LIMIT 0, 4 UNION SELECT * FROM media WHERE id >= 7 ORDER BY id ASC LIMIT 0, 6 ) as A ORDER BY A.id
Code:#1221 - Incorrect usage of UNION and ORDER BY
-
Nov 28, 2009, 19:19 #6
- Join Date
- May 2007
- Location
- Poole, UK
- Posts
- 5,077
- Mentioned
- 103 Post(s)
- Tagged
- 0 Thread(s)
It might be the ORDER BYs in the union, one is ASC and the other is DESC, they might be conflicting try removing them but leaving in the ORDER BY that you have at the end.
Community Team Advisor
Forum Guidelines: Posting FAQ Signatures FAQ Self Promotion FAQ
Help the Mods: What's Fluff? Report Fluff/Spam to a Moderator
-
Nov 30, 2009, 03:07 #7Guido - Community Team Leader
The Votes Are In: The Winners of the 2013 Community Awards are...
Blog - Free Flash Slideshow Widget
Bookmarks