lupld Posted October 21, 2007 Share Posted October 21, 2007 eh, simple question I know, but it takes a while for new things to stick, and the library's closed on Sunday's... I need to look up 30 entries from a given number in a mysql query, the catch is, if it hits 1 I need it to jump to the highest number in the database, or if it hits the highest number then it goes to 1... I'm using a while loop to display the information... any ideas? btw, I'm making a quiz, and pulling questions out of a database by an id that auto increments... Quote Link to comment https://forums.phpfreaks.com/topic/74240-solved-find-highest-number-in-field/ Share on other sites More sharing options...
Barand Posted October 21, 2007 Share Posted October 21, 2007 SELECT MAX(id) FROM tablename will give the highest id value. If you want 30 randm questions for a quiz you could try SELECT * FROM tablename ORDER BY RAND() LIMIT 30 Quote Link to comment https://forums.phpfreaks.com/topic/74240-solved-find-highest-number-in-field/#findComment-375036 Share on other sites More sharing options...
lupld Posted October 21, 2007 Author Share Posted October 21, 2007 K, thanks, that should work... as a side note, I'm still marking this as complete, but do you know an easy way to keep from getting the same question twice? I've thought through a few complex methods, but none that seem rational for a proper code, just a few noobish work arounds... Quote Link to comment https://forums.phpfreaks.com/topic/74240-solved-find-highest-number-in-field/#findComment-375039 Share on other sites More sharing options...
lupld Posted October 21, 2007 Author Share Posted October 21, 2007 Actually, the random would work better, then I don't need to worry about it hitting the lowest or highest number... now to just keep out duplicates... Quote Link to comment https://forums.phpfreaks.com/topic/74240-solved-find-highest-number-in-field/#findComment-375045 Share on other sites More sharing options...
Barand Posted October 21, 2007 Share Posted October 21, 2007 It shouldn't give any duplicates, unless you have duplicate questions in the table Quote Link to comment https://forums.phpfreaks.com/topic/74240-solved-find-highest-number-in-field/#findComment-375050 Share on other sites More sharing options...
lupld Posted October 21, 2007 Author Share Posted October 21, 2007 cool.. just to test that I'm going to test it before I hit 30 questions and see if it one gives me 29 results though... j/k - thanks for the help... Quote Link to comment https://forums.phpfreaks.com/topic/74240-solved-find-highest-number-in-field/#findComment-375080 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.