yuso6363 Posted September 10, 2010 Share Posted September 10, 2010 I am trying to make a gumball machine on my site which gives you a gumball every time you click the button. This is the code I am using to generate a gumball: <?php $balltype = rand(1,50); if ($balltype = 1) { mysql_query("INSERT INTO usersitems2 (owner,item_id,parts_left,game) VALUES ('$userid','30978','1','1')"); $gummy = "You won a <b>Blue Gumball</b>."; $picture = '<img src="http://www.bubblemagic.co.cc/images/gumballs/gum_blue.gif" width="80" height="80" border="0">'; } elseif ($balltype = 2) { mysql_query("INSERT INTO usersitems2 (owner,item_id,parts_left,game) VALUES ('$userid','30978','1','1')"); $gummy = "You won a <b>Blue Gumball</b>."; $picture = '<img src="http://www.bubblemagic.co.cc/images/gumballs/gum_blue.gif" width="80" height="80" border="0">'; } elseif ($balltype = 3) { mysql_query("INSERT INTO usersitems2 (owner,item_id,parts_left,game) VALUES ('$userid','30978','1','1')"); $gummy = "You won a <b>Blue Gumball</b>."; $picture = '<img src="http://www.bubblemagic.co.cc/images/gumballs/gum_blue.gif" width="80" height="80" border="0">'; } elseif ($balltype = 4) { mysql_query("INSERT INTO usersitems2 (owner,item_id,parts_left,game) VALUES ('$userid','30978','1','1')"); $gummy = "You won a <b>Blue Gumball</b>."; $picture = '<img src="http://www.bubblemagic.co.cc/images/gumballs/gum_blue.gif" width="80" height="80" border="0">'; } elseif ($balltype = 5) { mysql_query("INSERT INTO usersitems2 (owner,item_id,parts_left,game) VALUES ('$userid','30983','1','1')"); $gummy = "You won a <b>Green Gumball</b>."; $picture = '<img src="http://www.bubblemagic.co.cc/images/gumballs/gum_green.gif" width="80" height="80" border="0">'; } elseif ($balltype = 6) { mysql_query("INSERT INTO usersitems2 (owner,item_id,parts_left,game) VALUES ('$userid','30983','1','1')"); $gummy = "You won a <b>Green Gumball</b>."; $picture = '<img src="http://www.bubblemagic.co.cc/images/gumballs/gum_green.gif" width="80" height="80" border="0">'; } elseif ($balltype = 7) { mysql_query("INSERT INTO usersitems2 (owner,item_id,parts_left,game) VALUES ('$userid','30983','1','1')"); $gummy = "You won a <b>Green Gumball</b>."; $picture = '<img src="http://www.bubblemagic.co.cc/images/gumballs/gum_green.gif" width="80" height="80" border="0">'; } elseif ($balltype = { mysql_query("INSERT INTO usersitems2 (owner,item_id,parts_left,game) VALUES ('$userid','30983','1','1')"); $gummy = "You won a <b>Green Gumball</b>."; $picture = '<img src="http://www.bubblemagic.co.cc/images/gumballs/gum_green.gif" width="80" height="80" border="0">'; } elseif ($balltype = 9) { mysql_query("INSERT INTO usersitems2 (owner,item_id,parts_left,game) VALUES ('$userid','30985','1','1')"); $gummy = "You won an <b>Orange Gumball</b>."; $picture = '<img src="http://www.bubblemagic.co.cc/images/gumballs/gum_orange.gif" width="80" height="80" border="0">'; } elseif ($balltype = 10) { mysql_query("INSERT INTO usersitems2 (owner,item_id,parts_left,game) VALUES ('$userid','30985','1','1')"); $gummy = "You won an <b>Orange Gumball</b>."; $picture = '<img src="http://www.bubblemagic.co.cc/images/gumballs/gum_orange.gif" width="80" height="80" border="0">'; } elseif ($balltype = 11) { mysql_query("INSERT INTO usersitems2 (owner,item_id,parts_left,game) VALUES ('$userid','30985','1','1')"); $gummy = "You won an <b>Orange Gumball</b>."; $picture = '<img src="http://www.bubblemagic.co.cc/images/gumballs/gum_orange.gif" width="80" height="80" border="0">'; } elseif ($balltype = 12) { mysql_query("INSERT INTO usersitems2 (owner,item_id,parts_left,game) VALUES ('$userid','30985','1','1')"); $gummy = "You won an <b>Orange Gumball</b>."; $picture = '<img src="http://www.bubblemagic.co.cc/images/gumballs/gum_orange.gif" width="80" height="80" border="0">'; } elseif ($balltype = 13) { mysql_query("INSERT INTO usersitems2 (owner,item_id,parts_left,game) VALUES ('$userid','30986','1','1')"); $gummy = "You won a <b>Purple Gumball</b>."; $picture = '<img src="http://www.bubblemagic.co.cc/images/gumballs/gum_purple.gif" width="80" height="80" border="0">'; } elseif ($balltype = 14) { mysql_query("INSERT INTO usersitems2 (owner,item_id,parts_left,game) VALUES ('$userid','30986','1','1')"); $gummy = "You won a <b>Purple Gumball</b>."; $picture = '<img src="http://www.bubblemagic.co.cc/images/gumballs/gum_purple.gif" width="80" height="80" border="0">'; } elseif ($balltype = 15) { mysql_query("INSERT INTO usersitems2 (owner,item_id,parts_left,game) VALUES ('$userid','30986','1','1')"); $gummy = "You won a <b>Purple Gumball</b>."; $picture = '<img src="http://www.bubblemagic.co.cc/images/gumballs/gum_purple.gif" width="80" height="80" border="0">'; } elseif ($balltype = 16) { mysql_query("INSERT INTO usersitems2 (owner,item_id,parts_left,game) VALUES ('$userid','30986','1','1')"); $gummy = "You won a <b>Purple Gumball</b>."; $picture = '<img src="http://www.bubblemagic.co.cc/images/gumballs/gum_purple.gif" width="80" height="80" border="0">'; } elseif ($balltype = 17) { mysql_query("INSERT INTO usersitems2 (owner,item_id,parts_left,game) VALUES ('$userid','30990','1','1')"); $gummy = "You won a <b>Yellow Gumball</b>."; $picture = '<img src="http://www.bubblemagic.co.cc/images/gumballs/gum_yellow.gif" width="80" height="80" border="0">'; } elseif ($balltype = 18) { mysql_query("INSERT INTO usersitems2 (owner,item_id,parts_left,game) VALUES ('$userid','30990','1','1')"); $gummy = "You won a <b>Yellow Gumball</b>."; $picture = '<img src="http://www.bubblemagic.co.cc/images/gumballs/gum_yellow.gif" width="80" height="80" border="0">'; } elseif ($balltype = 19) { mysql_query("INSERT INTO usersitems2 (owner,item_id,parts_left,game) VALUES ('$userid','30990','1','1')"); $gummy = "You won a <b>Yellow Gumball</b>."; $picture = '<img src="http://www.bubblemagic.co.cc/images/gumballs/gum_yellow.gif" width="80" height="80" border="0">'; } elseif ($balltype = 20) { mysql_query("INSERT INTO usersitems2 (owner,item_id,parts_left,game) VALUES ('$userid','30990','1','1')"); $gummy = "You won a <b>Yellow Gumball</b>."; $picture = '<img src="http://www.bubblemagic.co.cc/images/gumballs/gum_yellow.gif" width="80" height="80" border="0">'; } elseif ($balltype = 21) { mysql_query("INSERT INTO usersitems2 (owner,item_id,parts_left,game) VALUES ('$userid','30981','1','1')"); $gummy = "You won a <b>Cola Gumball</b>."; $picture = '<img src="http://www.bubblemagic.co.cc/images/gumballs/gum_cola.gif" width="80" height="80" border="0">'; } elseif ($balltype = 22) { mysql_query("INSERT INTO usersitems2 (owner,item_id,parts_left,game) VALUES ('$userid','30981','1','1')"); $gummy = "You won a <b>Cola Gumball</b>."; $picture = '<img src="http://www.bubblemagic.co.cc/images/gumballs/gum_cola.gif" width="80" height="80" border="0">'; } elseif ($balltype = 23) { mysql_query("INSERT INTO usersitems2 (owner,item_id,parts_left,game) VALUES ('$userid','30981','1','1')"); $gummy = "You won a <b>Cola Gumball</b>."; $picture = '<img src="http://www.bubblemagic.co.cc/images/gumballs/gum_cola.gif" width="80" height="80" border="0">'; } elseif ($balltype = 24) { mysql_query("INSERT INTO usersitems2 (owner,item_id,parts_left,game) VALUES ('$userid','30979','1','1')"); $gummy = "You won a <b>Chocolate Gumball</b>."; $picture = '<img src="http://www.bubblemagic.co.cc/images/gumballs/gum_bronze.gif" width="80" height="80" border="0">'; } elseif ($balltype = 25) { mysql_query("INSERT INTO usersitems2 (owner,item_id,parts_left,game) VALUES ('$userid','30979','1','1')"); $gummy = "You won a <b>Chocolate Gumball</b>."; $picture = '<img src="http://www.bubblemagic.co.cc/images/gumballs/gum_bronze.gif" width="80" height="80" border="0">'; } elseif ($balltype = 26) { mysql_query("INSERT INTO usersitems2 (owner,item_id,parts_left,game) VALUES ('$userid','30979','1','1')"); $gummy = "You won a <b>Chocolate Gumball</b>."; $picture = '<img src="http://www.bubblemagic.co.cc/images/gumballs/gum_bronze.gif" width="80" height="80" border="0">'; } elseif ($balltype = 27) { mysql_query("INSERT INTO usersitems2 (owner,item_id,parts_left,game) VALUES ('$userid','30984','1','1')"); $gummy = "You won an <b>Ice Gumball</b>."; $picture = '<img src="http://www.bubblemagic.co.cc/images/gumballs/gum_ice.gif" width="80" height="80" border="0">'; } elseif ($balltype = 28) { mysql_query("INSERT INTO usersitems2 (owner,item_id,parts_left,game) VALUES ('$userid','30984','1','1')"); $gummy = "You won an <b>Ice Gumball</b>."; $picture = '<img src="http://www.bubblemagic.co.cc/images/gumballs/gum_ice.gif" width="80" height="80" border="0">'; } elseif ($balltype = 29) { mysql_query("INSERT INTO usersitems2 (owner,item_id,parts_left,game) VALUES ('$userid','30984','1','1')"); $gummy = "You won an <b>Ice Gumball</b>."; $picture = '<img src="http://www.bubblemagic.co.cc/images/gumballs/gum_ice.gif" width="80" height="80" border="0">'; } elseif ($balltype = 30) { mysql_query("INSERT INTO usersitems2 (owner,item_id,parts_left,game) VALUES ('$userid','30987','1','1')"); $gummy = "You won a <b>Rock Gumball</b>."; $picture = '<img src="http://www.bubblemagic.co.cc/images/gumballs/gum_rock.gif" width="80" height="80" border="0">'; } elseif ($balltype = 31) { mysql_query("INSERT INTO usersitems2 (owner,item_id,parts_left,game) VALUES ('$userid','30987','1','1')"); $gummy = "You won a <b>Rock Gumball</b>."; $picture = '<img src="http://www.bubblemagic.co.cc/images/gumballs/gum_rock.gif" width="80" height="80" border="0">'; } elseif ($balltype = 32) { mysql_query("INSERT INTO usersitems2 (owner,item_id,parts_left,game) VALUES ('$userid','30987','1','1')"); $gummy = "You won a <b>Rock Gumball</b>."; $picture = '<img src="http://www.bubblemagic.co.cc/images/gumballs/gum_rock.gif" width="80" height="80" border="0">'; } elseif ($balltype = 33) { mysql_query("INSERT INTO usersitems2 (owner,item_id,parts_left,game) VALUES ('$userid','30988','1','1')"); $gummy = "You won a <b>Strawberry Gumball</b>."; $picture = '<img src="http://www.bubblemagic.co.cc/images/gumballs/gum_strawberry.gif" width="80" height="80" border="0">'; } elseif ($balltype = 34) { mysql_query("INSERT INTO usersitems2 (owner,item_id,parts_left,game) VALUES ('$userid','30988','1','1')"); $gummy = "You won a <b>Strawberry Gumball</b>."; $picture = '<img src="http://www.bubblemagic.co.cc/images/gumballs/gum_strawberry.gif" width="80" height="80" border="0">'; } elseif ($balltype = 35) { mysql_query("INSERT INTO usersitems2 (owner,item_id,parts_left,game) VALUES ('$userid','30988','1','1')"); $gummy = "You won a <b>Strawberry Gumball</b>."; $picture = '<img src="http://www.bubblemagic.co.cc/images/gumballs/gum_strawberry.gif" width="80" height="80" border="0">'; } elseif ($balltype = 36) { mysql_query("INSERT INTO usersitems2 (owner,item_id,parts_left,game) VALUES ('$userid','30980','1','1')"); $gummy = "You won a <b>Dark Chocolate Gumball</b>."; $picture = '<img src="http://www.bubblemagic.co.cc/images/gumballs/gum_chocolate2.gif" width="80" height="80" border="0">'; } elseif ($balltype = 37) { mysql_query("INSERT INTO usersitems2 (owner,item_id,parts_left,game) VALUES ('$userid','30980','1','1')"); $gummy = "You won a <b>Dark Chocolate Gumball</b>."; $picture = '<img src="http://www.bubblemagic.co.cc/images/gumballs/gum_chocolate2.gif" width="80" height="80" border="0">'; } elseif ($balltype = 38) { mysql_query("INSERT INTO usersitems2 (owner,item_id,parts_left,game) VALUES ('$userid','30977','1','1')"); $gummy = "You won a <b>Black Gumball</b>."; $picture = '<img src="http://www.bubblemagic.co.cc/images/gumballs/gum_black.gif" width="80" height="80" border="0">'; } elseif ($balltype = 39) { mysql_query("INSERT INTO usersitems2 (owner,item_id,parts_left,game) VALUES ('$userid','30977','1','1')"); $gummy = "You won a <b>Black Gumball</b>."; $picture = '<img src="http://www.bubblemagic.co.cc/images/gumballs/gum_black.gif" width="80" height="80" border="0">'; } elseif ($balltype = 40) { mysql_query("INSERT INTO usersitems2 (owner,item_id,parts_left,game) VALUES ('$userid','30982','1','1')"); $gummy = "You won a <b>Digital Gumball</b>."; $picture = '<img src="http://www.bubblemagic.co.cc/images/gumballs/gum_digital.gif" width="80" height="80" border="0">'; } elseif ($balltype = 41) { mysql_query("INSERT INTO usersitems2 (owner,item_id,parts_left,game) VALUES ('$userid','30982','1','1')"); $gummy = "You won a <b>Digital Gumball</b>."; $picture = '<img src="http://www.bubblemagic.co.cc/images/gumballs/gum_digital.gif" width="80" height="80" border="0">'; } elseif ($balltype = 42) { mysql_query("INSERT INTO usersitems2 (owner,item_id,parts_left,game) VALUES ('$userid','30989','1','1')"); $gummy = "You won a <b>Silver Gumball</b>."; $picture = '<img src="http://www.bubblemagic.co.cc/images/gumballs/gum_silver.gif" width="80" height="80" border="0">'; } elseif ($balltype = 43) { mysql_query("INSERT INTO usersitems2 (owner,item_id,parts_left,game) VALUES ('$userid','30991','1','1')"); $gummy = "You won a <b>Burnt Gumball</b>. Ur... Well done..."; $picture = '<img src="http://www.bubblemagic.co.cc/images/gumballs/gumball_burnt.gif" width="80" height="80" border="0">'; } elseif ($balltype = 44) { mysql_query("INSERT INTO usersitems2 (owner,item_id,parts_left,game) VALUES ('$userid','30991','1','1')"); $gummy = "You won a <b>Burnt Gumball</b>. Ur... Well done..."; $picture = '<img src="http://www.bubblemagic.co.cc/images/gumballs/gumball_burnt.gif" width="80" height="80" border="0">'; } elseif ($balltype = 45) { mysql_query("INSERT INTO usersitems2 (owner,item_id,parts_left,game) VALUES ('$userid','30991','1','1')"); $gummy = "You won a <b>Burnt Gumball</b>. Ur... Well done..."; $picture = '<img src="http://www.bubblemagic.co.cc/images/gumballs/gumball_burnt.gif" width="80" height="80" border="0">'; } elseif ($balltype = 46) { mysql_query("INSERT INTO usersitems2 (owner,item_id,parts_left,game) VALUES ('$userid','30991','1','1')"); $gummy = "You won a <b>Burnt Gumball</b>. Ur... Well done..."; $picture = '<img src="http://www.bubblemagic.co.cc/images/gumballs/gumball_burnt.gif" width="80" height="80" border="0">'; } elseif ($balltype = 47) { mysql_query("INSERT INTO usersitems2 (owner,item_id,parts_left,game) VALUES ('$userid','30991','1','1')"); $gummy = "You won a <b>Burnt Gumball</b>. Ur... Well done..."; $picture = '<img src="http://www.bubblemagic.co.cc/images/gumballs/gumball_burnt.gif" width="80" height="80" border="0">'; } elseif ($balltype = 48) { mysql_query("INSERT INTO usersitems2 (owner,item_id,parts_left,game) VALUES ('$userid','30991','1','1')"); $gummy = "You won a <b>Burnt Gumball</b>. Ur... Well done..."; $picture = '<img src="http://www.bubblemagic.co.cc/images/gumballs/gumball_burnt.gif" width="80" height="80" border="0">'; } elseif ($balltype = 49) { mysql_query("INSERT INTO usersitems2 (owner,item_id,parts_left,game) VALUES ('$userid','30991','1','1')"); $gummy = "You won a <b>Burnt Gumball</b>. Ur... Well done..."; $picture = '<img src="http://www.bubblemagic.co.cc/images/gumballs/gumball_burnt.gif" width="80" height="80" border="0">'; } elseif ($balltype = 50) { mysql_query("INSERT INTO usersitems2 (owner,item_id,parts_left,game) VALUES ('$userid','30991','1','1')"); $gummy = "You won a <b>Burnt Gumball</b>. Ur... Well done..."; $picture = '<img src="http://www.bubblemagic.co.cc/images/gumballs/gumball_burnt.gif" width="80" height="80" border="0">'; } else { $gummy = "Nooooooooo!!!!! The gumball machine is broken!!! It still took your money though..."; } ?> Every time I try it, it gives me a burnt gumball EDIT: All that CODE hurts.... use some CODE formatting for godsakes. Quote Link to comment https://forums.phpfreaks.com/topic/213078-gumball-machine/ Share on other sites More sharing options...
Pikachu2000 Posted September 10, 2010 Share Posted September 10, 2010 if( $balltype == . . . Quote Link to comment https://forums.phpfreaks.com/topic/213078-gumball-machine/#findComment-1109697 Share on other sites More sharing options...
mikosiko Posted September 10, 2010 Share Posted September 10, 2010 in addition... - check what do you have in "$balltype = 8" is not showing the 8 - take a look also to the SWITCH() function - all your lines mysql_xxx can be replaced just for 1 line... is just a matter to manage the second VALUE in your insert and the color as variables (this is an improvement for version 2 ) Quote Link to comment https://forums.phpfreaks.com/topic/213078-gumball-machine/#findComment-1109699 Share on other sites More sharing options...
yuso6363 Posted September 10, 2010 Author Share Posted September 10, 2010 Thank you sooooooooooo much! I've been stuck on that for absolutely ages and you guys solved it in seconds of me posting! I love this site, Yuso6363 p.s. it works now. Quote Link to comment https://forums.phpfreaks.com/topic/213078-gumball-machine/#findComment-1109708 Share on other sites More sharing options...
.josh Posted September 10, 2010 Share Posted September 10, 2010 I feel violated. Quote Link to comment https://forums.phpfreaks.com/topic/213078-gumball-machine/#findComment-1109710 Share on other sites More sharing options...
yuso6363 Posted September 10, 2010 Author Share Posted September 10, 2010 why? Quote Link to comment https://forums.phpfreaks.com/topic/213078-gumball-machine/#findComment-1109712 Share on other sites More sharing options...
Philip Posted September 10, 2010 Share Posted September 10, 2010 I want a gumball! Quote Link to comment https://forums.phpfreaks.com/topic/213078-gumball-machine/#findComment-1109713 Share on other sites More sharing options...
yuso6363 Posted September 10, 2010 Author Share Posted September 10, 2010 http://www.bubblemagic.com/gumball.php sorry, no real ones. only digital. Quote Link to comment https://forums.phpfreaks.com/topic/213078-gumball-machine/#findComment-1109714 Share on other sites More sharing options...
Maq Posted September 10, 2010 Share Posted September 10, 2010 http://www.bubblemagic.com/gumball.php sorry, no real ones. only digital. Broken link... Quote Link to comment https://forums.phpfreaks.com/topic/213078-gumball-machine/#findComment-1109716 Share on other sites More sharing options...
yuso6363 Posted September 10, 2010 Author Share Posted September 10, 2010 http://www.bubblemagic.co.cc/gumball.php I sometimes can't even remember my own website. Quote Link to comment https://forums.phpfreaks.com/topic/213078-gumball-machine/#findComment-1109717 Share on other sites More sharing options...
Mchl Posted September 10, 2010 Share Posted September 10, 2010 I feel violated. I don't feel anymore. I'm completely numb... Quote Link to comment https://forums.phpfreaks.com/topic/213078-gumball-machine/#findComment-1109720 Share on other sites More sharing options...
yuso6363 Posted September 10, 2010 Author Share Posted September 10, 2010 poor you :'( Quote Link to comment https://forums.phpfreaks.com/topic/213078-gumball-machine/#findComment-1109721 Share on other sites More sharing options...
premiso Posted September 10, 2010 Share Posted September 10, 2010 *premiso dies a little inside. Because I am feeling extremely nice, here is an updated version of your code. $ballTypes = array(30978 => "Blue", 30983 => "Green", 30985 => "Orange", 30986 => "Purple", 30990 => "Yellow", 30981 => 'Cola', 30979 => 'Chocolate', 30984 => 'Ice', 30987 => 'Rock', 30988 => 'Strawberry', 30980 => 'Dark Chocolate', 30977 => 'Black', 30982 => 'Digital', 30989 => 'Silver', 30991 => 'Burnt'); $random_ball = array_rand($ballTypes); mysql_query("INSERT INTO usersitems2 (owner,item_id,parts_left,game) VALUES ('$userid','" . $ballTypes[$random_ball] . "','1','1')"); $gummy = "You won a <b>" . $ballTypes[$random_ball] . " Gumball</b>."; $picture = '<img src="http://www.bubblemagic.co.cc/images/gumballs/gum_' . str_replace("dark chocolate", "chocolate2", strtolower($ballTypes[$random_ball])) . '.gif" width="80" height="80" border="0">'; Think of how much easier this will be to maintain! Just try and keep the image titles similar to the ball name, as you can see with the str_replace, had to do a little hack for dark chocolate. If you named the image gum_dark-chocolate that would be much easier to handle. Either or, should help you out a bit. Quote Link to comment https://forums.phpfreaks.com/topic/213078-gumball-machine/#findComment-1109723 Share on other sites More sharing options...
Philip Posted September 10, 2010 Share Posted September 10, 2010 Awww premiso being nice? Something is wrong with that picture! On a side note: mysql_query("INSERT INTO usersitems2 (owner,item_id,parts_left,game) VALUES ('$userid','" . $ballTypes[$random_ball] . "','1','1')"); should read mysql_query("INSERT INTO usersitems2 (owner,item_id,parts_left,game) VALUES ('$userid','" . $random_ball . "','1','1')"); yes? Quote Link to comment https://forums.phpfreaks.com/topic/213078-gumball-machine/#findComment-1109725 Share on other sites More sharing options...
Mchl Posted September 10, 2010 Share Posted September 10, 2010 I actually wrote a slightly improved code, but I see others hava already posted even better versions. Quote Link to comment https://forums.phpfreaks.com/topic/213078-gumball-machine/#findComment-1109726 Share on other sites More sharing options...
premiso Posted September 10, 2010 Share Posted September 10, 2010 Awww premiso being nice? Something is wrong with that picture! should read mysql_query("INSERT INTO usersitems2 (owner,item_id,parts_left,game) VALUES ('$userid','" . $random_ball . "','1','1')"); yes? Yep, my mistake forgot we were using the key as the id Quote Link to comment https://forums.phpfreaks.com/topic/213078-gumball-machine/#findComment-1109730 Share on other sites More sharing options...
yuso6363 Posted September 10, 2010 Author Share Posted September 10, 2010 thanks for your help! does anyone know how to make some gumballs come out more often than others? Yuso6363 Quote Link to comment https://forums.phpfreaks.com/topic/213078-gumball-machine/#findComment-1109756 Share on other sites More sharing options...
premiso Posted September 10, 2010 Share Posted September 10, 2010 That is a bit more difficult and advanced I believe it is called "weighted probability": http://20bits.com/articles/random-weighted-elements-in-php/ http://www.gidforums.com/t-6365.html http://stackoverflow.com/questions/1105143/php-weight-algorithm All are decent resources to read about it. Quote Link to comment https://forums.phpfreaks.com/topic/213078-gumball-machine/#findComment-1109759 Share on other sites More sharing options...
fortnox007 Posted September 11, 2010 Share Posted September 11, 2010 I haven't read the links provided yet in the post before this one (i certainly will and thanks btw But I think a from of weighted probability can be achieved by setting up a range of items and let some items appear more often than others. Just like French roulette with two or 3 zero's (making the bank win in long term) so to make it more visible: this is the range: [ 1,2,3,4,5,6,7,2,1,1 ] if you would do a random within this range it would be obvious 1 will show up more often than 2 and 2 more often than the rest. With a longer range you can make it more precise of course. This is just what farted out of my brain. Hope it may be of any help. And I bet there are better ways : ) Quote Link to comment https://forums.phpfreaks.com/topic/213078-gumball-machine/#findComment-1109837 Share on other sites More sharing options...
yuso6363 Posted September 11, 2010 Author Share Posted September 11, 2010 there probably are better ways since I am making 50 possible things happen but my brain is more suited to long repetitive and boring sequences than short, hard bits of code. :-\ thanks again for all your help :'( you guys are so nice yuso6363 Quote Link to comment https://forums.phpfreaks.com/topic/213078-gumball-machine/#findComment-1109887 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.