Jump to content

Archived

This topic is now archived and is closed to further replies.

Phailak

While with 2 conditions

Recommended Posts

Hi,

I need to know how to make a while loop with two conditions from a query. There might be a better way to do this if any one has a suggestion.
Basically I want to display the scores from a hockey game (hockey league I run) and the idea is to have Home Team scorers on the left, Away Team Scorers on the right. I don't want to skip lines from Home Team scorers to Away Team scorers unless one side has more results (see [a href=\"http://www.lshl.net/Results_20060119_2040_233.html\" target=\"_blank\"]http://www.lshl.net/Results_20060119_2040_233.html[/a] which was generated through static pages)

Anyway, here's part of the code, please keep in mind I have little knowledge of PHP except through trial and error AND I put in RED the areas I thought might need some work (IFs and WHILE):

[code]$queryH="SELECT PlayerName, Penalty, PIM, Period, Time FROM penalties INNER JOIN players ON penalties.PlayerID = players.PlayerID WHERE GameID = $tgID AND penalties.TeamID = $HomeTeam UNION SELECT players.PlayerName, ifnull(AssistPlayer.PlayerName,'Unassisted') as Assist, '' as Other, Period, Time FROM goals INNER JOIN players ON goals.PlayerID = players.PlayerID LEFT JOIN players AssistPlayer ON goals.AssistID = AssistPlayer.PlayerID WHERE GameID = $tgID AND goals.TeamID = $HomeTeam ORDER BY Period, Time DESC";
$resultH=mysql_query($queryH);
$queryA="SELECT PlayerName, Penalty, PIM, Period, Time FROM penalties INNER JOIN players ON penalties.PlayerID = players.PlayerID WHERE GameID = $tgID AND penalties.TeamID = $AwayTeam UNION SELECT players.PlayerName, ifnull(AssistPlayer.PlayerName,'Unassisted') as Assist, '' as Other, Period, Time FROM goals INNER JOIN players ON goals.PlayerID = players.PlayerID LEFT JOIN players AssistPlayer ON goals.AssistID = AssistPlayer.PlayerID WHERE GameID = $tgID AND goals.TeamID = $AwayTeam ORDER BY Period, Time DESC";
$resultA=mysql_query($queryA);
[color=#FF0000]while($rowH=mysql_fetch_array($resultH) OR $rowA=mysql_fetch_array($resultA))[/color]
{
echo "<tr>\n";
    [color=#FF0000]if($rowY=mysql_fetch_array($resultH))[/color]
    {
    echo "<td align='center'width='15%'>".$rowH['PlayerName']."</td>";
    echo "<td align='center' width='15%'>".$rowH['Penalty']."</td>";
    echo "<td align='center' width='15%'>".$rowH['Time']."</td>";
    }
    ELSE
    {
    echo "<td align='center'width='15%'></td>";
    echo "<td align='center' width='15%'></td>";
    echo "<td align='center' width='15%'></td>";    
    }

    [color=#FF0000]if($rowZ=mysql_fetch_array($resultA))[/color]
    {
    echo "<td align='center'width='15%'>".$rowA['PlayerName']."</td>";
    echo "<td align='center' width='15%'>".$rowA['Penalty']."</td>";
    echo "<td align='center' width='15%'>".$rowA['Time']."</td>";
    }
    ELSE
    {
    echo "<td align='center'width='15%'></td>";
    echo "<td align='center' width='15%'></td>";
    echo "<td align='center' width='15%'></td>";    
    }

echo "</tr>\n";
}

echo "</table>\n";[/code]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.