What I want to do is use mt_rand() to choose a random number which at the start will be 1 and 2, it would check if that number is used a certain amount of times (in my case 25), if the number was taken that many times then change the random int from 1-2 to whatever number wasnt taken and 3(removing the numbers that were used 25 times from the mt_rand() function).It would keep going up and up until it found a league that wasn't full and would then insert the random number into a table (which I've already got working). The rest I've got working(also before answering, I know about security issues and will fix it as soon as I've got all the code working)
So here's the code:
<?php
$servername = getenv('IP');
$username = getenv('C9_USER');
$passwordp = "";
$database = "leaguescores";
$dbport = 3306;
// Create connection
$db = mysql_connect($servername, $username, $passwordp, $dbport)or die("Cant Connect to server");
mysql_select_db($database) or die("Cant connect to database");
$name = mysql_real_escape_string($_GET['name'], $db);
$amountinleague = "SELECT `leaguenum` FROM `leaguescores`.`silverleaguescores` WHERE leaguenum = $leaguenumber";
$score = mysql_real_escape_string($_GET['score'], $db);
$random = mt_rand(1, 2);
if($score >= 100){
$query2 = "INSERT INTO `leaguescores`.`silverleaguescores` (`id`, `name`, `score`) VALUES (NULL, '', ''), (NULL, '$name', '$score')";
$result2 = mysql_query($query2) or die('Query Failed: ' . mysql_error());
}else{
$amountofpplinleague = "SELECT COUNT(*) FROM `leaguescores`.`bronzeleaguescores` WHERE leaguenum = $random";
if($amountofpplinleague == 25){
//Change $random
}
$query = "INSERT INTO `leaguescores`.`bronzeleaguescores` (`id`, `name`, `score`) VALUES (NULL, '', ''), (NULL, '$name', '$score')";
$result = mysql_query($query) or die('Query Failed: ' . mysql_error());
}
?>
Aucun commentaire:
Enregistrer un commentaire