SitePoint Sponsor |
|
User Tag List
Results 1 to 10 of 10
Thread: Next 50 Records
-
Oct 8, 2009, 10:19 #1
- Join Date
- Mar 2005
- Posts
- 231
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Next 50 Records
How do I grab the next 50 records in a database without an autoincrement value?
-
Oct 8, 2009, 12:10 #2
- Join Date
- Aug 2008
- Location
- The Netherlands
- Posts
- 9,097
- Mentioned
- 153 Post(s)
- Tagged
- 3 Thread(s)
Rémon - Hosting Advisor
SitePoint forums will switch to Discourse soon! Make sure you're ready for it!
Minimal Bookmarks Tree
My Google Chrome extension: browsing bookmarks made easy
-
Oct 8, 2009, 13:28 #3
- Join Date
- Jul 2002
- Location
- Toronto, Canada
- Posts
- 39,347
- Mentioned
- 63 Post(s)
- Tagged
- 3 Thread(s)
-
Oct 13, 2009, 12:46 #4
- Join Date
- Mar 2005
- Posts
- 231
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
With respect to any random record in the database,
It can be the 50 after or the 50 before.
This is for an SEO function i'd like to make. Is this even possible?
Something tells me the min/max() functions should be able to do this?
Hm
-
Oct 13, 2009, 12:49 #5
- Join Date
- Mar 2005
- Posts
- 231
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Does mysql have a row_number function?
Gosh, I wish the rows were numbered then I'd just use a limit clause at the end of my next select
-
Oct 13, 2009, 12:58 #6
- Join Date
- Jul 2002
- Location
- Toronto, Canada
- Posts
- 39,347
- Mentioned
- 63 Post(s)
- Tagged
- 3 Thread(s)
-
Oct 13, 2009, 13:49 #7
- Join Date
- Mar 2005
- Posts
- 231
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Got it, hence I asked if Mysql had a row_number function to dynamatically assign row indexes?
Perhaps further explanation is in order... i have a parts database without auto-increment values. EAch time i query a partnumber, I'd also like to query the next 50 or X parts around it.
For instance if my part # is PX5400, i'd like to make another single query for PX5401 through PX5450 in the same run.
Does that make more sense? Any advice to how I could accomplish this given the first part# (PX4400). ?
-
Oct 13, 2009, 17:18 #8
- Join Date
- Jul 2002
- Location
- Toronto, Canada
- Posts
- 39,347
- Mentioned
- 63 Post(s)
- Tagged
- 3 Thread(s)
aha, finally we find something that can be used as a comparison to determine "noxt 50 by what" -- by increasing part number
so you needCode:SELECT ... FROM ... ORDER BY partnumber LIMIT x,y
-
Oct 13, 2009, 18:39 #9
- Join Date
- Mar 2005
- Posts
- 231
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
-
Oct 13, 2009, 20:54 #10
- Join Date
- Jul 2006
- Location
- Augusta, Georgia, United States
- Posts
- 4,194
- Mentioned
- 17 Post(s)
- Tagged
- 5 Thread(s)
Your "could" use GROUP_CONCAT() then explode and search for the index of the selected part. Then splice that array starting at the index and ending 50 items away. Then implode that array and embed it into a WHERE clause using an IN condition against the index. The only problem you would run into is when there aren't 50 item following the current one. In that case you could start from the beginning again if you "must" have 50 items.
Bookmarks