Jump to content

Archived

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

Petsmacker

Deal or no Deal remake - need help

Recommended Posts

Ok, basically I'm making a mini-PHP-game for my website based on the show 'Deal or no Deal'. On the UK version the prizes are:

1p, 10p, 50p, £1, £5, £10, £50, £100, £250, £500, £750, £1000, £3000, £5000, £10,000, £15,000, £20,000, £35,000, £50,000, £75,000, 100,000, £250,000

That is 22 different prize values and lo and behold - I have 22 cells in my database for each game (box1, box2, box3...box22).

What I want is that when a game is created the prize values go into the database however, none can be repeated, there can only be one each prize in each game, its important that the prizes go into random cells in the database so members can play again and again (there's a league table and whatnot).

I hope somebody can help with this. If its handy, the name of my Deal or no Deal table is called '[b]dond[/b]'.

1p would need to be represented in the database as 0.01, 10p = 0.10p and 5000 as 5000. Easy.

Thanks :)

Share this post


Link to post
Share on other sites
Found this at [a href=\"http://us3.php.net/mt_rand\" target=\"_blank\"]http://us3.php.net/mt_rand[/a]

[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]
Sometimes you need a bunch of unique random numbers and they have to be in a certain small range, here's a simple script that uses an array to remember the numbers generated before:

<?php

$randomNumbers = array(); // storage array
for ($i=0;$i<20;$i++) {
$random = mt_rand(0,30);
while(in_array($random,$randomNumbers)) {
$random = mt_rand(0,30); }
array_push($randomNumbers,$random);
echo $random;
}

?>

This way, when the while() function finds that the generated number is already in the storage array, it will automatically generate another one until no same number is found, thus eliminating any possibilities of having multiple same numbers... but still random.
[/quote]

With a little tweaking it should do the trick (use it to randomiz the cell as well as the prize).

Lite...

Share this post


Link to post
Share on other sites
Thankies, I've managed to get unique random numbers but don't know how to get the exact prize values into the database, as I want the actual values in the database.

Share this post


Link to post
Share on other sites
This is the script I've kicked up for the moment:

[code]<?
$randomNumbers = array(); // storage array
for ($i=0;$i<22;$i++) {
$random = mt_rand(1,22);
while(in_array($random,$randomNumbers)) {
$random = mt_rand(1,22); }
array_push($randomNumbers,$random);
echo "$random";
echo "<br>";
}

$randomNumbers2 = array(); // storage array
for ($i2=0;$i2<22;$i2++) {
$random2 = mt_rand(1,22);
while(in_array($random2,$randomNumbers2)) {
$random2 = mt_rand(1,22); }
array_push($randomNumbers2,$random2);
echo "<font color=\"red\">$random2</font>";
echo "<br>";
}

if ($random == 1){$t=0.01;}
if ($random == 2){$t=0.10;}
if ($random == 3){$t=0.50;}
if ($random == 4){$t=1;}
if ($random == 5){$t=5;}
if ($random == 6){$t=10;}
if ($random == 7){$t=50;}
if ($random == 8){$t=100;}
if ($random == 9){$t=250;}
if ($random == 10){$t=500;}
if ($random == 11){$t=750;}
if ($random == 12){$t=1000;}
if ($random == 13){$t=3000;}
if ($random == 14){$t=5000;}
if ($random == 15){$t=10000;}
if ($random == 16){$t=15000;}
if ($random == 17){$t=20000;}
if ($random == 18){$t=35000;}
if ($random == 19){$t=50000;}
if ($random == 20){$t=75000;}
if ($random == 21){$t=100000;}
if ($random == 22){$t=250000;}

echo "SQL: UPDATE dond SET box$random2='$t' WHERE name='$realname'";
?>[/code]

But I can't get it to do what I want, can anyone help?

Share this post


Link to post
Share on other sites
try something like
[code]
$prizes = array(
    0.01, 0.10, 0.50, 1, 5, 10, 50, 100, 250, 500, 750, 1000,
    3000, 5000, 10000, 15000, 20000, 35000, 50000, 75000, 100000, 250000
);

$dbprizes = $prizes; // copy the array and shuffle it
shuffle($dbprizes);

$vals = join (',', $dbprizes);
mysql_query("INSERT INTO mytable VALUES ($vals))";[/code]

Share this post


Link to post
Share on other sites

×

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.