Weird thing happening in my loop...
Posted: Mon Jan 07, 2008 9:18 pm
As always, thanks in advance for your help. I have a page that is returning participant information form the database including a TINYINT field which should return either 0 or a 1. The issue is that even when a participant has that value set to 0 in the database, it still appears in the loop as a 1. I wanted to debug to see if the variable was coming in correctly so I hardcoded a value to return a record with a 0 and it echoes correctly (at the bottom of my code below). The declared variable I am trying to loop is $Active = $ReturnedParticipants['Active']; After looking at this for quite some while I can not figure out what I am doing wrong in my loop. Does it have something to do with the field being a TINYINT. In SQL I would normally use a BIT setup for the field but I was unable to insert a 1 or 0 value in that field once created. It kept reading as a BLOB which is somehting I must say I am not aware of.
Code: Select all
<?PHP
$ParticipantQuery = "select * from tbParticipants p left join tbTeams t on t.TeamID = p.TeamID left join tbDivisions d on d.DivisionID = t.DivisionID left join tbParticipantType pt on pt.ParticipantType = p.ParticipantType order by p.LastName";
$FindParticipants = mysql_query($ParticipantQuery);
echo "<table align='center' border='1'>
<tr>
<td>Jersey #</td>
<td>First Name</td>
<td>Last Name</td>
<td>Email</td>
<td>Type</td>
<td>Division</td>
<td>Team</td>
<td>Active</td>
<td>Action</td>
</tr>
";
while ($ReturnedParticipants = mysql_fetch_assoc($FindParticipants))
{
$JerseyNumber = $ReturnedParticipants['JerseyNumber'];
$FirstName = $ReturnedParticipants['FirstName'];
$LastName = $ReturnedParticipants['LastName'];
$Email = $ReturnedParticipants['Email'];
$ParticipantType = $ReturnedParticipants['Description'];
$Division = $ReturnedParticipants['DivisionName'];
$Team = $ReturnedParticipants['TeamName'];
$Active = $ReturnedParticipants['Active'];
$ParticipantID = $ReturnedParticipants['ParticipantID'];
echo "
<tr>
<td>$JerseyNumber</td>
<td>$FirstName</td>
<td>$LastName</td>
<td><a href='mailto:$Email'>$Email</a></td>
<td>$ParticipantType</td>
<td>$Division</td>
<td>$Team</td>
<td>$Active</td>
<td><a href='edit_participant.php?ParticipantID=$ParticipantID'>edit</a></td>
</tr>
";
}
echo "</table>"
?>
<?PHP
//This is a test of the $Active variable=========================================================
$TestQuery = "select * from tbParticipants where ParticipantID = '1'";
$Query = mysql_query($TestQuery);
$TestValue = mysql_fetch_assoc($Query);
$Test = $TestValue['Active'];
echo $Test;
//This is a test of the $Active variable=========================================================
?>