Weird thing happening in my loop...

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
dgny06
Forum Commoner
Posts: 25
Joined: Thu Jun 14, 2007 11:35 pm

Weird thing happening in my loop...

Post 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=========================================================
?>
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

You are joining tables. Does the other table have and column named Active?
(#10850)
dgny06
Forum Commoner
Posts: 25
Joined: Thu Jun 14, 2007 11:35 pm

Post 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?
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

You may want to use AS and do something like:

Code: Select all

SELECT tbParticipants.Active AS participantActive, tbTeams.Active AS teamActive, ...
(#10850)
User avatar
Mordred
DevNet Resident
Posts: 1579
Joined: Sun Sep 03, 2006 5:19 am
Location: Sofia, Bulgaria

Re: Weird thing happening in my loop...

Post 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 ?
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Re: Weird thing happening in my loop...

Post 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
Post Reply