Page 1 of 1

Weird thing happening in my loop...

Posted: Mon Jan 07, 2008 9:18 pm
by dgny06
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=========================================================
?>

Posted: Mon Jan 07, 2008 10:15 pm
by Christopher
You are joining tables. Does the other table have and column named Active?

Posted: Mon Jan 07, 2008 10:30 pm
by dgny06
OMG....I can not believe I did not think of that.....ok....that brings me to another question....in this case where I have to be more specific with my column headers, I noticed that I can not do what I used to do in MS-SQL which would bring me here to $Active = $ReturnedParticipants['p.Active'];

However that returns no result at all....How would I do that in PHP?

Posted: Tue Jan 08, 2008 12:39 am
by Christopher
You may want to use AS and do something like:

Code: Select all

SELECT tbParticipants.Active AS participantActive, tbTeams.Active AS teamActive, ...

Re: Weird thing happening in my loop...

Posted: Tue Jan 08, 2008 12:50 am
by Mordred
dgny06 wrote: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.
[s]BIT----->[/s] BOOL ?

Re: Weird thing happening in my loop...

Posted: Tue Jan 08, 2008 3:32 pm
by superdezign
Mordred wrote:[s]BIT----->[/s] BOOL ?
I think BIT, BOOL, BOOLEAN, and TINYINT(1) are all the same. I'm sure that TINYINT(1) and BOOL are, at least.

I was more curious as to how you created the arrow than really needing to make a response though. Creative. :P