Jump to content

[SOLVED] RAND() problem.


NArc0t1c

Recommended Posts

Hello.

 

I'm sitting here with a problem I cannot seem to pass.

What I am trying to do is select data from row, ordered by it's rank.

So, that means, the higher the rank, the more likeley it will be picked.

Here is my query sofar;

select `id`,`name`,`image`,`url`,`mid`,`status` FROM `people` where `status`='1' order by rand(`rank`) limit 1

 

I have read the mysql documentation of the rand function, but I don;t know/can't find info on this.

Is it maybe that it can only handle numbers, if so, won't it return a number in any case.

The type of `rank` is int and set to 10 characters.

 

Edit: Oh yes.., the error; #1210 - Incorrect arguments to RAND

 

I really need help on this.

Thanks

Ferdi

Link to comment
https://forums.phpfreaks.com/topic/68756-solved-rand-problem/
Share on other sites

That's impossible to do with the RAND() function alone... it can only take a seed for the random number generator.

 

You'd need to "group" them into bins, then pick a random one from the highest "bin".

Thankyou, fenway.

 

I will do that.

Link to comment
https://forums.phpfreaks.com/topic/68756-solved-rand-problem/#findComment-346812
Share on other sites

Archived

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

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.