galahad3
01-11-2012, 01:20 PM
I'm having some issues with a PHP script I've created for displaying users from a database table.
In simple terms, the page loads the images and some basic details of all users (from the $query call to the database), but for each user it should also determine whether or not the user is "available" (a form on the previous page allows people to pick dates and "day or night", the idea being that while all users are shown, those who match that availability have a "I'm available" image display, whereas those whose availability dfoesn't match have the "I'm NOT available" image show. The $checkuser SQL query runs to determine which users are available.
My problem is that the "Available" image displays for users regardless of whether or not the user is available or not.
I echoed the $checkuser script and it's carrying through the variables ok, and no error message occurs.
It looks as if the if ($availableuser == $username) bit isn't working- or it's assigning $availableuser regardless of whether or not it matches the user.
Any ideas?
include ('inc/dbconnect.php');
if($_POST['checkavailability'])
{
$type=@$_POST['_Type'];
$date=@$_POST['_DateSelected'];
$daynight=@$_POST['_Time'];
// Build SQL Query
$query = "select RealName, Detail, ImageAvailable, ImageUnavailable from users"; // specify the table and field names for the SQL query
$numresults=mysql_query($query);
$numrows=mysql_num_rows($numresults);
// get results
$result = mysql_query($query) or die("Couldn't execute query");
echo '<table cellpadding="0" cellspacing="0" width="700" border="0"><tr>';
// display the results returned
while ($row= mysql_fetch_array($result)) {
$username= $row["UserName"];
$realname= $row["RealName"];
$detail= $row["Detail"];
$imageavailable= $row["ImageAvailable"];
$imageunavailable= $row["ImageUnavailable"];
$checkuser = "SELECT UserName FROM dates WHERE DateAvailable='$date' AND DayNight='$daynight'"; //Check to see if there are Locals
available
//echo $query;
//echo $checkuser;
$checkresult = mysql_query($checkuser) or die("Couldn't execute query");
while ($row= mysql_fetch_array($checkresult)) {
$availableuser= $row["UserName"];
$count++ ;
}
echo '<td align="left" width="200">' . $realname. '<br>' . $detail. '</td>';
if ($availableuser == $username)
{
echo '<td><img src="images/' . $imageavailable . '" width="100" height="150"></td>';
}
if (!$username == $availableuser)
{
echo '<td><img src="images/' . $imageunavailable . '" width="100" height="150"></td>';
}
if ( ($count % 3) == 0 ) {
echo '</tr><tr>';
}
$count++ ;
}
echo '</tr></table>';
}
In simple terms, the page loads the images and some basic details of all users (from the $query call to the database), but for each user it should also determine whether or not the user is "available" (a form on the previous page allows people to pick dates and "day or night", the idea being that while all users are shown, those who match that availability have a "I'm available" image display, whereas those whose availability dfoesn't match have the "I'm NOT available" image show. The $checkuser SQL query runs to determine which users are available.
My problem is that the "Available" image displays for users regardless of whether or not the user is available or not.
I echoed the $checkuser script and it's carrying through the variables ok, and no error message occurs.
It looks as if the if ($availableuser == $username) bit isn't working- or it's assigning $availableuser regardless of whether or not it matches the user.
Any ideas?
include ('inc/dbconnect.php');
if($_POST['checkavailability'])
{
$type=@$_POST['_Type'];
$date=@$_POST['_DateSelected'];
$daynight=@$_POST['_Time'];
// Build SQL Query
$query = "select RealName, Detail, ImageAvailable, ImageUnavailable from users"; // specify the table and field names for the SQL query
$numresults=mysql_query($query);
$numrows=mysql_num_rows($numresults);
// get results
$result = mysql_query($query) or die("Couldn't execute query");
echo '<table cellpadding="0" cellspacing="0" width="700" border="0"><tr>';
// display the results returned
while ($row= mysql_fetch_array($result)) {
$username= $row["UserName"];
$realname= $row["RealName"];
$detail= $row["Detail"];
$imageavailable= $row["ImageAvailable"];
$imageunavailable= $row["ImageUnavailable"];
$checkuser = "SELECT UserName FROM dates WHERE DateAvailable='$date' AND DayNight='$daynight'"; //Check to see if there are Locals
available
//echo $query;
//echo $checkuser;
$checkresult = mysql_query($checkuser) or die("Couldn't execute query");
while ($row= mysql_fetch_array($checkresult)) {
$availableuser= $row["UserName"];
$count++ ;
}
echo '<td align="left" width="200">' . $realname. '<br>' . $detail. '</td>';
if ($availableuser == $username)
{
echo '<td><img src="images/' . $imageavailable . '" width="100" height="150"></td>';
}
if (!$username == $availableuser)
{
echo '<td><img src="images/' . $imageunavailable . '" width="100" height="150"></td>';
}
if ( ($count % 3) == 0 ) {
echo '</tr><tr>';
}
$count++ ;
}
echo '</tr></table>';
}