switch?
Posted: Sat Jan 24, 2009 7:47 pm
Ok, I have this code. It is meant to run as a cronjob. It is supposed to run, check each players rank, then add turns to each account dependent upon which rank the have.
The script work to an extent. However, it will only execute the case "Member". I originally had the member case set and a default instead of a case without the member clasification. It would only execute the default on all members meaning everyone recived only 15 turns.
I then changed the default into case "member" leaving it where it was (at the bottom). Tested it, and again it was only adding 15 turns to all players.
I then moved the case "member" to the start of the script thinking that maybe it was executing the final case every time. I was wrong, even when moving the case to the top of the script it was still the only one to be executed.
If anyone might be able to tell me what I am doing wrong, please let me know.
Thank you in advance.
The script work to an extent. However, it will only execute the case "Member". I originally had the member case set and a default instead of a case without the member clasification. It would only execute the default on all members meaning everyone recived only 15 turns.
I then changed the default into case "member" leaving it where it was (at the bottom). Tested it, and again it was only adding 15 turns to all players.
I then moved the case "member" to the start of the script thinking that maybe it was executing the final case every time. I was wrong, even when moving the case to the top of the script it was still the only one to be executed.
Code: Select all
<?php
$config_server = "*******"; //Database host
$config_database = "*******"; //Database name
$config_username = "********"; //Database username
$config_password = "********"; //Database password
$secret_key = "********"; //Secret key, make it a random word/sentence/whatever
include('../adodb/adodb.inc.php'); //Include adodb files
$db = &ADONewConnection('mysql'); //Connect to database
$db->Connect($config_server, $config_username, $config_password, $config_database); //Select table
$db->SetFetchMode(ADODB_FETCH_ASSOC); //Fetch associative arrays
$ADODB_FETCH_MODE = ADODB_FETCH_ASSOC; //Fetch associative arrays
//$db->debug = true; //Debug
$query = $db->execute("select `rank` from `players` where `id`");
$player1 = $query->fetchrow();
foreach($player1 as $key=>$value)
{
$player->$key = $value;
}
switch ($player->rank)
{
case "Ghetto":
$query = $db->execute("update `players` set `turns`=turns + 30");
break;
case "Player":
$query = $db->execute("update `players` set `turns`=turns + 45");
break;
case "Pimp":
$query = $db->execute("update `players` set `turns`=turns + 60");
break;
case "OG":
$query = $db->execute("update `players` set `turns`=turns + 100");
break;
case "Member";
$query = $db->execute("update `players` set `turns`=turns + 15");
break;
}
?>
Thank you in advance.