There is probably a very simple fix to this, but i’m all new with php, and very ignorant.
I’ve been trying to get my head around this problem, but to no avail.
Here is the code :
echo $slot['slot_type'];
echo "<br><br>";
if ($slot['slot_type']='tree') echo "This place is full of life, and can be used for hunting, gathering, logging, or other activities.";
if ($slot['slot_type']='town_hall') echo "The town hall houses the governors, and is propriety of the King.";
if ($slot['slot_type']='farm1') echo "Townspeople attempt to grow a selection of wild plants on these crops, hoping for a steady food supply.";
if ($slot['slot_type']='farm2') echo "Farming is hard work, but a full storehouse of food is a great comfort.";
The first line with echo $slot['slot_type']; was my attempt to try and understand why my “if” statement does not work. However, it prints the proper string, in this case “tree”.
So, in practise, instead of printing one of the proposed text strings, the browser prints all four of them, as if it ignored my IF statements completely. Again, sorry for asking what looks like such a silly question.
You need to change all your single
=to==or some other logical check.What you are essentially doing is assigning
$slot['slot_type']the values on the right hand side of your condition which will always return true.Have a read of the php manual here http://uk.php.net/manual/en/language.operators.php
As an aside, your
ifstructures might be better created using aswitchstatement.