|
-
Jun 20th, 2004, 04:27 PM
#1
Take out a random record. [Resolved]
I have to take out 5 records from a MySQL table. First the 3 last one, and then 2 random records. But no one of them can be the same record. With my current skills I can see 2 methods to do it.
- I can store all the records that I have taken out, then use a while loop and take out a new random one untill I get a new one.
- I can use NOT LIKE (or what the syntax is again) and list up the first record that I have taken out the first time in the second one, and then the two first in the 3rd one, and the 3 first in the 4th one, and so on.
I can't see that any of them is a good solution. Maybe the second one is a bit faster, but that is all.
Is it a better way?
Last edited by NoteMe; Jun 21st, 2004 at 02:41 PM.
-
Jun 20th, 2004, 05:08 PM
#2
Frenzied Member
A very slight tweak on the first one:
make a random number, then keep making them until you have 5 different ones. then remove those records from the db. this will stop you having to do extra mysql stuff.
Have I helped you? Please Rate my posts. 
-
Jun 20th, 2004, 05:09 PM
#3
Ohhh yeah..that was a good one. Will try that one.
Thanks.
ØØ
-
Jun 21st, 2004, 07:18 AM
#4
Frenzied Member
Well, using the DISTINCT keyword would eliminate any duplicates, and then you could just pick randomly from those results.
-
Jun 21st, 2004, 02:40 PM
#5
Originally posted by ober0330
Well, using the DISTINCT keyword would eliminate any duplicates, and then you could just pick randomly from those results.
Not sure if I got you. There is no duplicated entries in the table. The problem is if I first take out 3 records, then I want 2 random ones, then I can get one of those I have all ready picked.
-
Jun 22nd, 2004, 09:04 AM
#6
Frenzied Member
Well what sort of thing are you doing? Why not take 5 out and then when you want the extra 2 later, you already have them and you're not going to get ones you already picked?
-
Jun 22nd, 2004, 09:44 AM
#7
Originally posted by ober0330
Well what sort of thing are you doing? Why not take 5 out and then when you want the extra 2 later, you already have them and you're not going to get ones you already picked?
Becase it's cd and 12" reviews. So we are showing the picture and the few first words from the 3 latest, then we pick 3 good one that have got 6points, that we show off at the bottom. So I can't do it that way. It was to be done in two searches at minimum.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|