HI,
i have created a script that randomly creates endtimes (of a race).
So like this :
PHP Code:
$endtime1=mt_rand(1,5);
and so on for 5times (so till $endtime5).
Endtime1 is the endtime of horse nr 1
Endtime2....................................2,...
The endtimes are written in the database in the table 'horsescores'.
(id(auto_increment),horsenr,endtime,rank).
In horsenr the number of the horse (1-5)is written. In the endtime column the endtimes are written.
I now want to write the rank (depending on the endtimes, so the horse with the smallest endtime is the winner, etcetc untill the loser (5th).
How can i do this?
I thought about selecting all horses and order them by endtime with an sql query but i don't exactly now how i can save that ordering in ranknumbers.
And maybe there is a better way?
because i want to make the game look real by adding an endtime into the scorebord.
But you're probably right and think i just realized what you mean.
Can i (on the scorebord), order them by endtime ASC and adding the corresponding rank in the 'rank' column?
How?
With an $i ?
And when it starts $i = 1 (so first), and use a while loop with $i++ everytime?
The decimal restrictions should only apply when the random number is either $minwhole or $maxwhole. When called with for ex. 20.8 and 30.9 you won't get a 25.1
__________________
I'm not sure if this was any help, but I hope it didn't make you stupider.
Experience is something you get just after you really need it. PHP Installation Guide Feedback welcome.
Hi Mwnciau & marek_mar
thank you both for your efforts in helping me
About your code, Mwnciau, when i tried it it only returned decimal numbers of .0 and .1 so( 174.1,154.1,4564.1:456465.1,......)
so that's not really what i wanted.
About your code marek_mar, seems to work perfectly random, but it prints float() and int() with it, can you delete that? Thank you (because i just want to store the value in a variable like for example $randnr=float_mt_rand(min,max); for that it should only be a number right? (sorry i'm a total noob )
Also about your code marek_mar, when i tried it (with your example numbers of min and max), i almost all the time gotnumbers 0,985 and 1,6 and never like 13.2. Why? (i don't understand your function ).
Also : i should have numbers varying between 9.12 and 14.1, should i just enter that numbers in the min and max?
About your code marek_mar, seems to work perfectly random, but it prints float() and int() with it, can you delete that? Thank you (because i just want to store the value in a variable like for example $randnr=float_mt_rand(min,max); for that it should only be a number right? (sorry i'm a total noob )
Yes, the int/float is from var_dump(). It is useful to know which type a variable has sometimes and that's why I use it.
Quote:
Originally Posted by arne2
Also about your code marek_mar, when i tried it (with your example numbers of min and max), i almost all the time gotnumbers 0,985 and 1,6 and never like 13.2. Why? (i don't understand your function ).
I'm sorry this is a bug. This is version is corrected.
thank you both i'm going to test it right away !
Could anyone of you comment your code because i tried but i can't really figure out what everything means.