modernmafia Posted June 5, 2012 Posted June 5, 2012 out come error You brake the window to the car and jump in[ car name here not shown ] a well done! it normally always shows car name but a odd occasion it come up with the text above and dont show the name but still inserts it into the garage with no name and value at 0 any ideas or where ive missed a bracket <?php session_start(); include 'includes/db_connect.php'; include 'includes/functions.php'; include 'includes/jail_check.php'; if ($info->last_script_check < time()){ include_once "probe.php"; } $username=$_SESSION['username']; $radiobutton=$_POST['radiobutton']; $above = mysql_query("SELECT * FROM users WHERE username='$username'"); $info = mysql_fetch_object($above); $chance = explode("-", $info->gtachance); if (strip_tags($_GET['reset'])){ $reset=strip_tags($_GET['reset']); if($info->points < "4"){ echo "<center><font color=red><b>You dont have enough credits to reset your gta timer!</td>"; }elseif($info->points >= "4"){ mysql_query("UPDATE users SET points=points-5, lastgta='' WHERE username='$username'"); echo "<center><font color=green><b>Your gta timer has now been reset!<br><meta http-equiv='refresh' content='1;url=gta.php'>"; }} if ($info->lastgta > time()){ $left = $info->lastgta - time(); echo "<script type='text/javascript' src='timer.js'></script><link href='style.css' rel='stylesheet' type='text/css'> <br><table width='30%' align='center' cellspacing='0' cellpadding=0 border=0 class='table'> <tr> <td colspan='6' class='header' align=left>Error!</center></td> </tr> <tr> <td align='center'>You have to wait <span id='crime5'></span><script type='text/javascript'>setTimer('crime5','$left', { 0: function () { window.location = 'gta.php' }}); </script> before you can commit another gta!<br><br><a href=?reset=gta>Reset Timer (Costs 5 Credits)!</a></label></td> </tr> </div></table>"; exit(); } if ($_POST['submit']){ $suc = $chance[$radiobutton]; $ran = rand(1,100); if ($ran <= $suc){ if ($radiobutton == "6"){ $success = $chance[0]; $cars = array('Vauxhall Nova','Vauxhall Corsa','Ford Fiesta ST','Renault Clio','Peugeot 206','Ford Focus ST','Nissan 350Z','Subaru Impreza WRX','Toyota Supra','Lamborghini Gallardo','Lamborghini Murcielago','Mercades SLR','Bugatti Veyron'); $quote="You Broke In To The House And Found The Keys To The Car"; ////NEXT RADIO }elseif ($radiobutton == "1"){ $success = $chance[1]; $cars = array('Vauxhall Nova','Vauxhall Corsa','Ford Fiesta ST','Renault Clio','Peugeot 206','Ford Focus ST','Nissan 350Z','Subaru Impreza WRX','Toyota Supra','Lamborghini Gallardo','Lamborghini Murcielago','Mercades SLR','Bugatti Veyron'); $quote="You Found A Car With Keys In It."; ////NEXT RADIO }elseif ($radiobutton == "2"){ $success = $chance[2]; $cars = array('Vauxhall Nova','Vauxhall Corsa','Ford Fiesta ST','Renault Clio','Peugeot 206','Ford Focus ST','Nissan 350Z','Subaru Impreza WRX','Toyota Supra','Lamborghini Gallardo','Lamborghini Murcielago','Mercades SLR','Bugatti Veyron'); $quote="You Managed To Get The Sexy Model To Give You The Keys And You Drove Away."; ////NEXT RADIO }elseif ($radiobutton == "4"){ $success = $chance[4]; $cars = array('Vauxhall Nova','Vauxhall Corsa','Ford Fiesta ST','Renault Clio','Peugeot 206','Ford Focus ST','Nissan 350Z','Subaru Impreza WRX','Toyota Supra','Lamborghini Gallardo','Lamborghini Murcielago','Mercades SLR','Bugatti Veyron'); $quote="You Drove The Car Out Of The Back Door With The Owner On The Bonnet"; ////NEXT RADIO }elseif ($radiobutton == "5"){ $success = $chance[5]; $cars = array('Vauxhall Nova','Vauxhall Corsa','Ford Fiesta ST','Renault Clio','Peugeot 206','Ford Focus ST','Nissan 350Z','Subaru Impreza WRX','Toyota Supra','Lamborghini Gallardo','Lamborghini Murcielago','Mercades SLR','Bugatti Veyron'); $quote="You Got The Car Out Of The Crews Car Lot With Out Being Seen."; } $win=rand(1,13); if ($cars[$win] == "Vauxhall Nova"){ $na = "images/car/nova.jpg"; } elseif ($cars[$win] == "Vauxhall Corsa"){ $na = "images/car/corsa.jpg"; } elseif ($cars[$win] == "Ford Fiesta ST"){ $na = "images/car/fiesta.jpg"; } elseif ($cars[$win] == "Renault Clio"){ $na = "images/car/clio.jpg"; } elseif ($cars[$win] == "Peugeot 206"){ $na = "images/car/206.jpg"; } elseif ($cars[$win] == "Ford Focus ST"){ $na = "images/car/focus.jpg"; } elseif ($cars[$win] == "Nissan 350Z"){ $na = "images/car/350z.jpg"; } elseif ($cars[$win] == "Subaru Impreza WRX"){ $na = "images/car/wrx.jpg"; } elseif ($cars[$win] == "Toyota Supra"){ $na = "images/car/supra.jpg"; } elseif ($cars[$win] == "Lamborghini Gallardo"){ $na = "images/cars/lambog.jpg"; } elseif ($cars[$win] == "Lamborghini Murcielago"){ $na = "images/cars/lambom.jpg"; } elseif ($cars[$win] == "Mercades SLR"){ $na = "images/cars/slr.jpg"; } elseif ($cars[$win] == "Bugatti Veyron"){ $na = "images/cars/veyron.jpg"; } echo "<link href='style.css' rel='stylesheet' type='text/css'><br><center> <table width='30%' align='center' cellspacing='0' cellpadding=0 border=0 class='table'> <tr> <td colspan='6' class='header' align=left>Succesful!</center></td> </tr> <tr> <td align='center'>You brake the window to the car and jump in a $cars[$win] well done!</label></td> </tr> </div></table>"; mysql_query("UPDATE user_info SET gtas=gtas+1 WHERE username='$username'"); mysql_query("UPDATE users SET GP=GP+1 WHERE username='$username'"); $time= time() + (60*5); if($site->doublexp == "ON"){ $newrank = $info->rankpoints + 22; $newrank2 = $info->rankpoints + 8; $newcomprank = $info->compxp + 22; $newcomprank2 = $info->compxp + 8; }else{ $newrank = $info->rankpoints + 12; $newrank2 = $info->rankpoints + 4; $newcomprank = $info->compxp + 12; $newcomprank2 = $info->compxp + 4; } $damage=rand(1,50); if ($cars[$win] == "Vauxhall Nova"){ $max="750"; if ($damage == "0"){ $for=$max; }elseif ($damage == "50"){ $for = "0"; }else{ $for = $max / $damage *2; } } ////////////////////////////////////// if ($cars[$win] == "Vauxhall Corsa"){ $max="3250"; if ($damage == "0"){ $for=$max; }elseif ($damage == "50"){ $for = "0"; }else{ $for = $max / $damage *2; } } ////////////////////////////////////// if ($cars[$win] == "Ford Fiesta ST"){ $max="3850"; if ($damage == "0"){ $for=$max; }elseif ($damage == "50"){ $for = "0"; }else{ $for = $max / $damage *2; } } ////////////////////////////////////// if ($cars[$win] == "Renault Clio"){ $max="4000"; if ($damage == "0"){ $for=$max; }elseif ($damage == "50"){ $for = "0"; }else{ $for = $max / $damage *2; } } ////////////////////////////////////// if ($cars[$win] == "Peugeot 206"){ $max="5000"; if ($damage == "0"){ $for=$max; }elseif ($damage == "50"){ $for = "0"; }else{ $for = $max / $damage *2; } } ////////////////////////////////////// if ($cars[$win] == "Ford Focus ST"){ $max="9000"; if ($damage == "0"){ $for=$max; }elseif ($damage == "50"){ $for = "0"; }else{ $for = $max / $damage *2; } } ////////////////////////////////////// if ($cars[$win] == "Nissan 350Z"){ $max="14000"; if ($damage == "0"){ $for=$max; }elseif ($damage == "50"){ $for = "0"; }else{ $for = $max / $damage *2; } } ////////////////////////////////////// if ($cars[$win] == "Subaru Impreza WRX"){ $max="15000"; if ($damage == "0"){ $for=$max; }elseif ($damage == "50"){ $for = "0"; }else{ $for = $max / $damage *2; } } ////////////////////////////////////// if ($cars[$win] == "Toyota Supra"){ $max="20000"; if ($damage == "0"){ $for=$max; }elseif ($damage == "50"){ $for = "0"; }else{ $for = $max / $damage *2; } } ////////////////////////////////////// if ($cars[$win] == "Lamborghini Gallardo"){ $max="53499"; if ($damage == "0"){ $for=$max; }elseif ($damage == "50"){ $for = "0"; }else{ $for = $max / $damage *2; } } ////////////////////////////////////// if ($cars[$win] == "Lamborghini Murcielago"){ $max="75000"; if ($damage == "0"){ $for=$max; }elseif ($damage == "50"){ $for = "0"; }else{ $for = $max / $damage *2; } } ////////////////////////////////////// if ($cars[$win] == "Mercades SLR"){ $max="95000"; if ($damage == "0"){ $for=$max; }elseif ($damage == "50"){ $for = "0"; }else{ $for = $max / $damage *2; } } ////////////////////////////////////// if ($cars[$win] == "Bugatti Veyron"){ $max="275000"; if ($damage == "0"){ $for=$max; }elseif ($damage == "50"){ $for = "0"; }else{ $for = $max / $damage *2; } } ////////////////////////////////////// $for=round($for); //print "$for!!"; mysql_query("INSERT INTO `garage` ( `id` , `owner` , `car` , `damage`,`origion`,`location`,`worth`) VALUES ( '', '$username', '$cars[$win]', '$damage','$info->location','$info->location','$max' )"); mysql_query("UPDATE users SET rankpoints='$newrank' WHERE username='$username'"); if ($site->xpcompstatus == "2"){ mysql_query("UPDATE users SET compxp=$newcomprank WHERE username='$username'"); } }else{ if ($radiobutton == "6"){ $quote="You Got No Way Near The Posh House The Dogs Scared You Away. You Got Away With Nothing"; }elseif ($radiobutton == "1"){ $quote="You Triped On The Curb And Set The Car Alarm Off. You Got Away With Nothing"; }elseif ($radiobutton == "2"){ $quote="You Got Caught Climbing In To The Car And You Were Taken Down By A Car Model. You Got Away With Nothing"; }elseif ($radiobutton == "4"){ $quote="The Car Lot Owner Saw You Go In To The Show Room After Dark And Followed You In. You Got Away With Nothing"; }elseif ($radiobutton == "5"){ $quote="The Crew Caught You Hiding In There Car Lot. You Got Away With Nothing"; } $reason = "Gta"; require_once "includes/failed.php"; echo "<link href='style.css' rel='stylesheet' type='text/css'><br><center> <table width='30%' align='center' cellspacing='0' cellpadding=0 border=0 class='table'> <tr> <td colspan='6' class='header' align=left>Failed!</center></td> </tr> <tr> <td align='center'>You tryed to steal the car but the police drove passed you failed to get away with a car!</label></td> </tr> </div></table>"; mysql_query("UPDATE user_info SET gtas=gtas+1 WHERE username='$username'"); } if($chance[0] == 1){$chance[1] = 1;} elseif(($chance[0] >= 1) && ($chance[0] <= 2)){$chance[0] = rand(1,$chance[0]);} elseif(($chance[0] >= 2) && ($chance[0] <= 10)){$chance[0] = rand(10,$chance[0]);} elseif(($chance[0] >= 5) && ($chance[0] <= 25)){$chance[0] = rand(25,$chance[0]);} elseif(($chance[0] >= 18) && ($chance[0] <= 36)){$chance[0] = rand(36,$chance[0]);} elseif(($chance[0] >= 25) && ($chance[0] <= 49)){$chance[0] = rand(49,$chance[0]);} elseif(($chance[0] >= 36) && ($chance[0] <= 58)){$chance[0] = rand(58,$chance[0]);} elseif(($chance[0] >= 49) && ($chance[0] <= 55)){$chance[0] = rand(55,$chance[0]);} elseif($chance[0] >= 55){$chance[0] = rand(55,$chance[0]);} if($chance[0] == 1){$chance[1] = 0;} elseif(($chance[0] >= 1) && ($chance[0] <= 2)){$chance[1] = rand(0,$chance[0]);} elseif(($chance[0] >= 3) && ($chance[0] <= 8)){$chance[1] = rand(7,$chance[0]);} elseif(($chance[0] >= 9) && ($chance[0] <= 15)){$chance[1] = rand(14,$chance[0]);} elseif(($chance[0] >= 16) && ($chance[0] <= 34)){$chance[1] = rand(33,$chance[0]);} elseif(($chance[0] >= 35) && ($chance[0] <= 74)){$chance[1] = rand(45,$chance[0]);} elseif($chance[0] >= 75){$chance[1] = rand(50,$chance[0]);} if($chance[0] == 1){$chance[2] = 0;} elseif(($chance[0] >= 1) && ($chance[0] <= 2)){$chance[2] = rand(0,$chance[0]);} elseif(($chance[0] >= 3) && ($chance[0] <= 8)){$chance[2] = rand(6,$chance[0]);} elseif(($chance[0] >= 9) && ($chance[0] <= 15)){$chance[2] = rand(13,$chance[0]);} elseif(($chance[0] >= 16) && ($chance[0] <= 34)){$chance[2] = rand(32,$chance[0]);} elseif(($chance[0] >= 35) && ($chance[0] <= 74)){$chance[2] = rand(60,$chance[0]);} elseif($chance[0] >= 75){$chance[2] = rand(85,$chance[0]);} if($chance[0] == 1){$chance[4] = 0;} elseif(($chance[0] >= 1) && ($chance[0] <= 2)){$chance[4] = rand(0,$chance[0]);} elseif(($chance[0] >= 3) && ($chance[0] <= 8)){$chance[4] = rand(6,$chance[0]);} elseif(($chance[0] >= 9) && ($chance[0] <= 15)){$chance[4] = rand(13,$chance[0]);} elseif(($chance[0] >= 16) && ($chance[0] <= 34)){$chance[4] = rand(32,$chance[0]);} elseif(($chance[0] >= 35) && ($chance[0] <= 74)){$chance[4] = rand(60,$chance[0]);} elseif($chance[0] >= 75){$chance[4] = rand(85,$chance[0]);} if($chance[0] == 1){$chance[5] = 0;} elseif(($chance[0] >= 1) && ($chance[0] <= 2)){$chance[5] = rand(0,$chance[0]);} elseif(($chance[0] >= 3) && ($chance[0] <= 8)){$chance[5] = rand(6,$chance[0]);} elseif(($chance[0] >= 9) && ($chance[0] <= 15)){$chance[5] = rand(13,$chance[0]);} elseif(($chance[0] >= 16) && ($chance[0] <= 34)){$chance[5] = rand(32,$chance[0]);} elseif(($chance[0] >= 35) && ($chance[0] <= 74)){$chance[5] = rand(60,$chance[0]);} elseif($chance[0] >= 75){$chance[5] = rand(85,$chance[0]);} if($chance[0] > 70){ $chance[0] = 40; } if($chance[1] > 70){ $chance[1] = 40; } if($chance[2] > 75){ $chance[2] = 40; } if($chance[4] > 85){ $chance[4] = 40; } if($chance[5] > 48){ $chance[5] = 40; } $chance[0]++; if ($chance[0] > 50){ $chance[0] = 40; } $arrayrates = array($chance[0], $chance[1], $chance[2], $chance[3], $chance[4], $chance[5]); $newrates = implode("-", $arrayrates); $tim = time() + (60*5); mysql_query("UPDATE users SET gtachance='$newrates',lastgta='$tim' WHERE username='$username'"); exit; } ?> <? if ($site->gupdate == "1"){ echo "<link href='style.css' rel='stylesheet' type='text/css'><center><div class='update'>$site->gupdatetext</div></center> <br>"; } ?> <script type="text/javascript"> var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www."); document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E")); </script> <script type="text/javascript"> try { var pageTracker = _gat._getTracker("UA-12456885-1"); pageTracker._trackPageview(); } catch(err) {}</script> <script type="text/javascript"> if(!top || top.frames.length < 4) { top.location="/index2.php";} </script> <link href="style.css" rel="stylesheet" type="text/css"> <script language=JavaScript> function so(dis) { for (i=0;i<dis.elements.length;i++){ if (dis.elements[i].type=='submit') dis.elements[i].style.visibility='hidden'; } if(fs==false){ fs=true; return true; }else return false; } function goaway() { for(i=0;i<document.forms.length;i++) document.forms[i].onsubmit = function() {return so(this);}; } </script> <style > .bar_cont { display: inline-block; vertical-align:middle; } .bar { position: relative; width: 150px; line-height: 11px; border: 1px solid #000; color: #000000; background: url('images/crimebg/red.jpg'); background-repeat: repeat-x; } .rg { position: relative; height: 11px; background-image: url('images/crimebg/green.jpg'); background-repeat: repeat-x; z-index: 2; } </style> </head> <body onLoad="goaway();"> <form name="form1" method="post" action=""> <table width="300" align="center" border="0" cellpadding="0" cellspacing="0" class="table"> <tr class="header"> <td colspan="2">GTA</td> </tr> <tr> <td align="center" width="20"><input type="radio" name="radiobutton" value="1"></td> <td>Street<br><div class="bar" align="left"><div class="per" align="left"><?php echo "$chance[1]"; ?>%</div><div class="rg" align="left" style="width:<?php echo "$chance[1]"; ?>%"></div></div></td> </tr> <tr> <td align="center"><input type="radio" name="radiobutton" value="2"></td> <td>Car Park: <div class="bar" align="left"><div class="per" align="left"><?php echo "$chance[2]"; ?>%</div><div class="rg" align="left" style="width:<?php echo "$chance[2]"; ?>%"></div></div></td> </tr> <tr> <td align="center"><input type="radio" name="radiobutton" value="4"></td> <td>Car Dealership: <div class="bar" align="left"><div class="per" align="left"><?php echo "$chance[4]"; ?>%</div><div class="rg" align="left" style="width:<?php echo "$chance[4]"; ?>%"></div></div></td> </tr> <tr> <td align="center"><input type="radio" name="radiobutton" value="5"></td> <td>Car manufacturer: <div class="bar" align="left"><div class="per" align="left"><?php echo "$chance[5]"; ?>%</div><div class="rg" align="left" style="width:<?php echo "$chance[5]"; ?>%"></div></div></td> </tr> <tr> <td colspan="2" align="center"> <div align="center"> <input name="submit" type="submit" class="button" id="submit" value="Steal Car"> </div></td> </tr> </table> </form> <p> </p> </html> Quote
modernmafia Posted June 5, 2012 Author Posted June 5, 2012 line 131 : $win=rand(1,13); is it to do with the random car selection Quote
Seker Posted June 5, 2012 Posted June 5, 2012 line 131 : $win=rand(1,13); is it to do with the random car selection Possibly, as it looks like you're trying to use a number to pick the car names. Quote
modernmafia Posted June 5, 2012 Author Posted June 5, 2012 Possibly, as it looks like you're trying to use a number to pick the car names. so if i put $win=rand(0,13); you think it would slove it cause it would select between 0 and 13 so it will pick from vaxuhall nova to the Bugatti Veyron or does the random need to be set high or lower Quote
modernmafia Posted June 5, 2012 Author Posted June 5, 2012 seker also thank you for taking the time to reply to my post Quote
Seker Posted June 5, 2012 Posted June 5, 2012 No, I believe the problem is trying to use a number, period. Your cars array uses the car names. I believe you'd have to use an ID number in your array instead of the car name, as I don't believe (Really just don't know for sure) there's a way to pull a random string. Wish I could be of more help or be more certain, but I'm fairly new to all this, and I haven't even touched arrays yet. Quote
modernmafia Posted June 5, 2012 Author Posted June 5, 2012 No, I believe the problem is trying to use a number, period. Your cars array uses the car names. I believe you'd have to use an ID number in your array instead of the car name, as I don't believe (Really just don't know for sure) there's a way to pull a random string. Wish I could be of more help or be more certain, but I'm fairly new to all this, and I haven't even touched arrays yet. no worries mate i appreciate your help and your time but hopefully some one else will pick the topic up :) thanks again Quote
Seker Posted June 5, 2012 Posted June 5, 2012 Found something on PHP.net. Now, realize, I have absolutely no idea if I've done this right, so you have like a 50/50 shot of it working. $win = substr(str_shuffle(str_repeat('Vauxhall Nova','Vauxhall Corsa','Ford Fiesta ST','Renault Clio','Peugeot 206','Ford Focus ST','Nissan 350Z','Subaru Impreza WRX','Toyota Supra','Lamborghini Gallardo','Lamborghini Murcielago','Mercades SLR','Bugatti Veyron',1)),0,1); Try replacing line 131 with that. Quote
Seker Posted June 5, 2012 Posted June 5, 2012 On a simpler note, if that is just completely wrong, I BELIEVE you could do something like this: $1 = 'Vauxhall Nova'; $2 = 'Vauxhall Corsa'; $3 = 'Ford Fiesta ST'; $4 = 'Renault Clio'; $5 = 'Peugeot 206'; $6 = 'Ford Focus ST'; $7 = 'Nissan 350Z'; $8 = 'Subaru Impreza WRX'; $9 = 'Toyota Supra'; $10 = 'Lamborghini Gallardo'; $11 = 'Lamborghini Murcielago'; $12 = 'Mercades SLR'; $13 = 'Bugatti Veyron'; $win = mt_rand(1,13); Then change: if ($cars[$win] == "Vauxhall Nova"){ $na = "images/car/nova.jpg"; } elseif ($cars[$win] == "Vauxhall Corsa"){ $na = "images/car/corsa.jpg"; } elseif ($cars[$win] == "Ford Fiesta ST"){ $na = "images/car/fiesta.jpg"; } elseif ($cars[$win] == "Renault Clio"){ $na = "images/car/clio.jpg"; } elseif ($cars[$win] == "Peugeot 206"){ $na = "images/car/206.jpg"; } elseif ($cars[$win] == "Ford Focus ST"){ $na = "images/car/focus.jpg"; } elseif ($cars[$win] == "Nissan 350Z"){ $na = "images/car/350z.jpg"; } elseif ($cars[$win] == "Subaru Impreza WRX"){ $na = "images/car/wrx.jpg"; } elseif ($cars[$win] == "Toyota Supra"){ $na = "images/car/supra.jpg"; } elseif ($cars[$win] == "Lamborghini Gallardo"){ $na = "images/cars/lambog.jpg"; } elseif ($cars[$win] == "Lamborghini Murcielago"){ $na = "images/cars/lambom.jpg"; } elseif ($cars[$win] == "Mercades SLR"){ $na = "images/cars/slr.jpg"; } elseif ($cars[$win] == "Bugatti Veyron"){ $na = "images/cars/veyron.jpg"; } To: if ($win == 1) {$win = $1; $na = "images/car/nova.jpg";} elseif ($win == 2) {$win = $2; $na = "images/car/corsa.jpg";} elseif ($win == 3) {$win = $3; $na = "images/car/fiesta.jpg";} elseif ($win == 4) {$win = $4; $na = "images/car/clio.jpg";} elseif ($win == 5) {$win = $5; $na = "images/car/206.jpg";} elseif ($win == 6) {$win = $6; $na = "images/car/focus.jpg";} elseif ($win == 7) {$win = $7; $na = "images/car/350z.jpg";} elseif ($win == 8) {$win = $8; $na = "images/car/wrx.jpg";} elseif ($win == 9) {$win = $9; $na = "images/car/supra.jpg";} elseif ($win == 10) {$win = $10; $na = "images/car/lambog.jpg";} elseif ($win == 11) {$win = $11; $na = "images/car/lambom.jpg";} elseif ($win == 12) {$win = $12; $na = "images/car/slr.jpg";} elseif ($win == 13) {$win = $13; $na = "images/car/veyron.jpg";} Maybe? And that's all I got. Hope SOMETHING works. :P Quote
modernmafia Posted June 5, 2012 Author Posted June 5, 2012 ill give it ago :) ill make a back up of my current one thanks again :) Quote
Djkanna Posted June 5, 2012 Posted June 5, 2012 (edited) $win=rand(0,12); Seker: You can use a number, in this case. $array = array ( 'zero', 'one', 'two', 'three'); $array[0]; // Zero $array[3]; // Three Edited June 5, 2012 by Djkanna Bah Quote
modernmafia Posted June 5, 2012 Author Posted June 5, 2012 $1 = 'Vauxhall Nova'; $2 = 'Vauxhall Corsa'; $3 = 'Ford Fiesta ST'; $4 = 'Renault Clio'; $5 = 'Peugeot 206'; $6 = 'Ford Focus ST'; $7 = 'Nissan 350Z'; $8 = 'Subaru Impreza WRX'; $9 = 'Toyota Supra'; $10 = 'Lamborghini Gallardo'; $11 = 'Lamborghini Murcielago'; $12 = 'Mercades SLR'; $13 = 'Bugatti Veyron'; this above line 131 $win = mt_rand(1,13); Quote
Seker Posted June 5, 2012 Posted June 5, 2012 $1 = 'Vauxhall Nova'; $2 = 'Vauxhall Corsa'; $3 = 'Ford Fiesta ST'; $4 = 'Renault Clio'; $5 = 'Peugeot 206'; $6 = 'Ford Focus ST'; $7 = 'Nissan 350Z'; $8 = 'Subaru Impreza WRX'; $9 = 'Toyota Supra'; $10 = 'Lamborghini Gallardo'; $11 = 'Lamborghini Murcielago'; $12 = 'Mercades SLR'; $13 = 'Bugatti Veyron'; this above line 131 $win = mt_rand(1,13); I believe so. Again, just a shot in the dark. Try the simple way, ie. what Djkanna just posted. :P Quote
modernmafia Posted June 5, 2012 Author Posted June 5, 2012 I believe so. Again, just a shot in the dark. Try the simple way, ie. what Djkanna just posted. :P well im sure one of you pro`s will be right :) Quote
Djkanna Posted June 5, 2012 Posted June 5, 2012 Modern; Use your original code, and just change the $win to a rand(0,12); You should no longer get the occasional unknown car. Quote
Seker Posted June 5, 2012 Posted June 5, 2012 $win=rand(0,12); Seker: You can use a number, in this case. $array = array ( 'zero', 'one', 'two', 'three'); $array[0]; // Zero $array[3]; // Three Ah okay then. As I said, I haven't touched arrays yet. Looks like I need to start. :P Quote
Djkanna Posted June 5, 2012 Posted June 5, 2012 Ah okay then. As I said, I haven't touched arrays yet. Looks like I need to start. :P :) One thing that trips people up is the position of elements in an array (as with this case) If you have 13 elements, the position of the last element will be 12, and the position of the first will be 0. Quote
modernmafia Posted June 5, 2012 Author Posted June 5, 2012 :) One thing that trips people up is the position of elements in an array (as with this case) If you have 13 elements, the position of the last element will be 12, and the position of the first will be 0. even though there is 13 cars ? Quote
Seker Posted June 5, 2012 Posted June 5, 2012 even though there is 13 cars ? 1 through 13 = 13. 0 through 12 = 13. Quote
Djkanna Posted June 5, 2012 Posted June 5, 2012 even though there is 13 cars ? Yes, as Seker just mentioned, 0 -> 12 = 13, 1 -> 13 = 13; Arrays start from 0 not from 1. Quote
modernmafia Posted June 5, 2012 Author Posted June 5, 2012 1 through 13 = 13. 0 through 12 = 13. oh so the value are the same but its better to use rand 0,12 then 0,13 Quote
modernmafia Posted June 5, 2012 Author Posted June 5, 2012 Yes, as Seker just mentioned, 0 -> 12 = 13, 1 -> 13 = 13; Arrays start from 0 not from 1. oh i see thats where i was going wrong so it was having problems selecting the wining car and inserting it into the database thats why the car name was not showing as the array was wrong Quote
Djkanna Posted June 5, 2012 Posted June 5, 2012 (edited) oh i see thats where i was going wrong so it was having problems selecting the wining car and inserting it into the database thats why the car name was not showing as the array was wrong If your $win variable returned 13, it would have issues, as there is no element at position 13 in your array. I am pretty sure, this would have thrown an error (undefined index maybe?), but if you've chosen to omit certain warnings then, perhaps you didn't get it. Edit: Either way take a look at PHP Manual: Arrays Edited June 5, 2012 by Djkanna Quote
modernmafia Posted June 5, 2012 Author Posted June 5, 2012 If your $win variable returned 13, it would have issues, as there is no element at position 13 in your array. I am pretty sure, this would have thrown an error (undefined index maybe?), but if you've chosen to omit certain warnings then, perhaps you didn't get it. Edit: Either way take a look at PHP Manual: Arrays no i didnt get it all it did was say you stole [no name here ] then it still inserts the no car name into the garage with 0 value but hopefully changing it to $win=rand(0,12); will sort the problem :) thanks as well Djkanna for your time and knowledge Quote
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.