Jump to content

PHP Output from MsSql query not working correctly


vbcoach

Recommended Posts

Hello.  Have an issue that has been bugging me for a couple of weeks now that I am just not figuring out.  I have a sports league site that has multiple leagues and divisions.  I have a looping statement that queries the leagues, returns the leagues (nights and divisions) with the number of those teams that are paid and also "locked in".  See screenshot #1 attached.

 

I have 4 queries written that are working properly when run from Sql Management Studio with the correct results displayed. 

 

$query2 = "SELECT  l_id, COUNT(*) as num_teams FROM league as l, team WHERE league = l_id AND reg_done != '' GROUP BY l_id,type,size,l.division,night ORDER BY l_id";
$paidTeams = mssql_query($query2,$conn);

$query3 = "SELECT l.type, l.[size], l.division, l.l_id, l.[session], COUNT(*) AS num_teams FROM league as l, team WHERE team.league = l.l_id AND (l.[session] = 'Summer') GROUP BY l.l_id, l.type, l.[size], l.division, l.night, l.[session] ORDER BY l.l_id";
$leagues2 = mssql_query($query3,$conn);

$query4 = "SELECT l.type, l.[size], l.division, l.l_id, l.[session], COUNT(*) AS num_teams FROM league as l, team WHERE team.league = l.l_id AND (l.[session] = 'Summer') AND reg_done != '' GROUP BY l.l_id, l.type, l.[size], l.division, l.night, l.[session] ORDER BY l.l_id";
$paidTeams2 = mssql_query($query4,$conn);

$query5 = "SELECT l.type, l.[size], l.division, l.l_id, l.[session], COUNT(*) AS num_teams FROM league as l, team WHERE team.league = l.l_id AND (l.[session] = 'Summer') and team.locked = '1' GROUP BY l.l_id, l.type, l.[size], l.division, l.night, l.[session] ORDER BY l.l_id";
$lockedteams = mssql_query($query5,$conn);

 

These results display correctly in MsSql, but not on my page.  No error is generated, just no results displayed, so I must concede that my code is wrong.  I could use your help discovering where my mistake is, and correct it.  There are currently 3 "locked in" teams:  2 in M4A Division and 1 in M4B Division.  Here is my PHP code:

 

<?php
  
  $paidt2 = mssql_fetch_assoc($paidTeams2);
  $lockedt = mssql_fetch_assoc($lockedteams);
      	  
   while($row = mssql_fetch_assoc($leagues2))
  {
    
  ?>
        <tr>
          <td><?php echo "$row[type] $row[size] $row[division]" ?></td>
          <td><div align="center"><?php echo $row['num_teams']; ?></div></td>
          <td><div align="center">
            <?php 
        
          if($row['l_id'] == $paidt2['l_id'])
	  {
	    echo "<strong> $paidt2[num_teams]</strong>"; 
		$paidt2 = mssql_fetch_assoc($paidTeams2);
		$lockedt = mssql_fetch_assoc($lockedteams);

			  } 
	  else
	    echo '-'; ?>
          </div></td>
          <td><div align="center">
            <?php 
        
          if($row['l_id'] == $lockedt['l_id'])
	  {
	    echo "<strong> $lockedt[num_teams]</strong>"; 
		$paidt2 = mssql_fetch_assoc($paidTeams2);
		$lockedt = mssql_fetch_assoc($lockedteams);

			  } 
	  else
	    echo '-'; ?>
          </div></td>
          <td width="10"> </td>
        </tr>
    <?php
  }
  ?>

 

Many thanks for your assistance!

 

[attachment deleted by admin]

Archived

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

×
×
  • Create New...

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.