Jump to content


Photo

Deal or no Deal remake - need help


  • Please log in to reply
5 replies to this topic

#1 Petsmacker

Petsmacker
  • Members
  • PipPipPip
  • Advanced Member
  • 71 posts

Posted 19 March 2006 - 04:37 AM

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 'dond'.

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

Thanks :)

#2 litebearer

litebearer
  • Members
  • PipPipPip
  • Advanced Member
  • 2,357 posts
  • Locationwhite lake michigan

Posted 19 March 2006 - 06:27 AM

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...

all the brothers were valiant!

[br][br]The truely intelligent people are not those who create the dots; rather they are they ones with the ability to connect the dots into a coherent picture

#3 Petsmacker

Petsmacker
  • Members
  • PipPipPip
  • Advanced Member
  • 71 posts

Posted 19 March 2006 - 06:55 AM

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.

#4 Petsmacker

Petsmacker
  • Members
  • PipPipPip
  • Advanced Member
  • 71 posts

Posted 19 March 2006 - 07:36 AM

This is the script I've kicked up for the moment:

<?
$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'";
?>

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

#5 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 19 March 2006 - 08:39 AM

try something like
$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))";

If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#6 Petsmacker

Petsmacker
  • Members
  • PipPipPip
  • Advanced Member
  • 71 posts

Posted 19 March 2006 - 08:51 AM

Yay! Thankies!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users