Hello,
I'm practicing PHP & mysql by making a small text based game (what else?). In my table 'users' there's a column called 'state' which is basically the player's type of government. I have a page called 'soldiers.php' where the player trains soldiers, if they have a government set to 'Police State' then the cost is 2.5 per soldier, otherwise, it's 3.
I made this code, to me it looks correct, but i've noticed it is always set to 2.5, regardless of what value $row['state'] is:
php
<?php
$user = $_SESSION['username']; // session for their username
$result = mysql_query("SELECT * FROM users WHERE username='$user'") or die(mysql_error());
$row = mysql_fetch_array($result);
$money = $row['money']; // how much money they have
$state = $row['state']; // what government they have
if ($state = 'Police State') {
$cost = 2.5; // reduced cost for specific government
} else {
$cost = 3; // normal cost for everything else
}
echo '<a class="style1">You have '.$money.' dinars. It costs '.$cost.' dinars per soldier.'; // cost is always displayed as 2.5 for some reason
?>
Thank you
EDIT: did a bit of thinking - do if statements not work on setting values for variables?
This post has been edited by Sayid Ahmed: 27 Aug, 2008 - 08:40 AM