Page 1 of 1

Matching two recordsets combined with if then statement

Posted: Tue Jul 17, 2007 3:12 pm
by apexonelove
Whaddup DevNetwork,

I'm working on a somewhat weird scripting dilemma I can't seem to get myself out of! Basically, I've got two recordsets which query my db and look for two things:

The first returns a list of all users.

The second checks my sessionID against a database table of of teammembers (memberID to membereeID) to see if the users listed are in the users team.

The problem is that I don't want it to filter or only show those results...as that would be far too easy :P. Basically, I want to be able to see the entire list and just put a notation (image or text) that states this person is on my team.

The pain in the side is that I've got it to work beautifully for the first record in the recordset. The problem is that it doesn't look past the first one.

So, finally, the question: Is there a way to loop through the recordset I'm trying to query my if then statement against? I've looked up looping, but that doesn't really seem to be the way to roll. I've also seen some loose resolutions in ASP, which doesn't help because I'm in PHP.

Any help would be simply amazing!

Here's the if/then statement code, hopefully it helps.

Code: Select all

<?php do { ?>			
<tr style="cursor: pointer;" class="menudef" onmouseover="this.className='menuOver'" onmouseout="this.className='menudef'" onclick="MM_goToURL('parent','teammemberdetails.php?ID=<?php echo $row_rsTeam['ID']; ?>');return document.MM_returnValue">
<td width="31" valign="top"><img src="images/teamvitars/<?php echo $row_rsTeam['ID']; ?>.jpg" width="30" height="30" /></td>
<td width="130" valign="top"><a href="teammemberdetails.php?ID=<?php echo $row_rsTeam['ID']; ?>">
<?php echo $row_rsTeam['Username']; ?>: </a><a href="teammemberdetails.php?ID=<?php echo $row_rsTeam['ID']; ?>"><?php echo $row_rsTeam['ID']; ?><br /></a> 
                
<?php
echo $counter ?>

<?php 
// Show IF They are in your team
if (@$row_rsTeam['ID'] == @$row_rsTeamLink['AccountID']) {
?>
They're in your team.
<?php 
// else Show that they are not
} else { ?>
They’re not in your team.
<?php } 
?>

<?php 
// Show IF This is you
if (@$row_rsTeam['ID'] == @$_SESSION['session_id']) {
?>
  This is you!
  <?php } 
// endif this is you condition
?></td>
                  </tr>
                  <?php } while ($row_rsTeam = mysql_fetch_assoc($rsTeam)); ?>

Posted: Tue Jul 17, 2007 3:17 pm
by hawleyjr
Hello apexonelove,

Welcome to the forum.

What does your query and table structure(s) look like?

Also, why did you decide to add the @ in front of your variables?

Code: Select all

if (@$row_rsTeam['ID'] == @$row_rsTeamLink['AccountID']) {

Posted: Tue Jul 17, 2007 3:35 pm
by apexonelove
Thanks so much for the quick and warm welcome!

Team Query:

Code: Select all

mysql_select_db($database_MDFFCHOP, $MDFFCHOP);
$query_rsTeam = "SELECT ID, Username, accnttype, signupdate FROM Accounts WHERE Accounts.accnttype = 'Basic Teammember' ORDER BY signupdate DESC";
$rsTeam = mysql_query($query_rsTeam, $MDFFCHOP) or die(mysql_error());
$row_rsTeam = mysql_fetch_assoc($rsTeam);
$totalRows_rsTeam = mysql_num_rows($rsTeam);
TeamLink Query:

Code: Select all

mysql_select_db($database_MDFFCHOP, $MDFFCHOP);
$query_rsTeamLink = sprintf("SELECT * FROM TeamLinktbl, Accounts WHERE TeamLinktbl.FriendID = %s AND TeamLinktbl.AccountID = Accounts.ID UNION SELECT * FROM TeamLinktbl, Accounts WHERE TeamLinktbl.AccountID = %s AND TeamLinktbl.FriendID = Accounts.ID", $varSearch_rsTeamLink,$varSearch_rsTeamLink);
$rsTeamLink = mysql_query($query_rsTeamLink, $MDFFCHOP) or die(mysql_error());
$row_rsTeamLink = mysql_fetch_assoc($rsTeamLink);
$totalRows_rsTeamLink = mysql_num_rows($rsTeamLink);
So, there are the queries. It's built loosely off of social networking principles. The TeamLinktbl has three columns

teamlinkid | AccountID | FriendID
Autogen | teamlead number | teamee number

So as you can see, the query i'm trying to do looks at my logged-in session id, then checks it to the teamlink table and filters out all of the results based off of that session id...then I'm now stuck looping through the results for the if, then statement. Just makes me sick to think that I've spent so many hours on this insanely simple thing! I guess that's success will be the payoff.
Also, why did you decide to add the @ in front of your variables?

php:

if (@$row_rsTeam['ID'] == @$row_rsTeamLink['AccountID']) {
This was just how it dropped in through dare I say it....Dreamweaver UltraDev. It does work without them. Thanks again![/b]