関数内から$row(データベース配列)を呼び出そうとしていますが、変数に基づいて列名を呼び出しています。
これが完全なコードです...あなたはで結果を見ることができます
http://tlcs.stuart-pinfold.co.uk/test.php?id=20
と
http://tlcs.stuart-pinfold.co.uk/test.php?id=21
<?php
include("includes/db.php"); // includes all the db connections
$id = $_GET['id'];
$sql = "SELECT * FROM users WHERE UserID='".$id."'";
$set = mysql_query($sql);
$row = mysql_fetch_array($set);
function checkAvailability($day)
{
$check = "UserCommute".$day;
if($row[$check]=="1")
{
echo '<img src="/tick.jpg" alt="Available on this day" />';
}
else
{
echo '<img src="/cross.jpg" alt="Not available on this day" />';
}
echo " = ".$check."<br/>";
}
echo "Full Name:<br/>".$row['UserFullName']; // this works perfectly
echo "<br/><br/>Using the function...<br/>";
echo checkAvailability('Mon');
echo checkAvailability('Tue');
echo checkAvailability('Wed');
echo checkAvailability('Thu');
echo checkAvailability('Fri');
echo checkAvailability('Sat');
echo checkAvailability('Sun'); // these always return a cross even when the database entry is 1
echo "<br/>Using hard-coded row values...<br/>";
echo $row['UserCommuteMon']." = UserCommuteMon<br/>";
echo $row['UserCommuteTue']." = UserCommuteTue<br/>";
echo $row['UserCommuteWed']." = UserCommuteWed<br/>";
echo $row['UserCommuteThu']." = UserCommuteThu<br/>";
echo $row['UserCommuteFri']." = UserCommuteFri<br/>";
echo $row['UserCommuteSat']." = UserCommuteSat<br/>";
echo $row['UserCommuteSun']." = UserCommuteSun<br/>"; // these work perfectly, returning 0s or 1s, matching the database
?>
クロスのみを返し、ティックは返しません。
どこが間違っているのですか?