Jump to content

Recommended Posts

My league does not keep scores and standings for younger ages.  How can alter my code to not display any recorded scores if confid < 11???

 

<?php
print "<table width='100%' class='tbl-border'>\n";
print "<tr><th class='tbl2'>Date</th><th class='tbl2'>Home Team</th><th class='tbl2'>Score</th><th class='tbl2'>Visiting Team</th><th class='tbl2'>Score</th>";
if ($show_fields) print "<th class='tbl2'>Field</th>\n";
$queryscores="SELECT sportsdb_wins.winid, sportsdb_wins.windate, sportsdb_wins.wintime, sportsdb_wins.game_date, sportsdb_wins.game_time, sportsdb_wins.rf, sportsdb_wins.ra, sportsdb_wins.wincomments, sportsdb_wins.field, sportsdb_wins.winortie, sportsdb_teams2.teamname AS winningteam, sportsdb_teams.teamname AS losingteam
FROM sportsdb_wins, sportsdb_teams AS sportsdb_teams2, sportsdb_teams, sportsdb_divs
WHERE sportsdb_teams.teamdiv = sportsdb_divs.divid AND sportsdb_divs.conference = $confid AND sportsdb_teams2.teamid = sportsdb_wins.winner AND sportsdb_teams.teamid = sportsdb_wins.loser AND sportsdb_wins.winortie != 3";

// Sort by team if specified
if (isset($_POST['teamtosort']) && $_POST['teamtosort'] != 'all') {
$teamtosort = intval($_POST['teamtosort']);
$queryscores .= " AND (sportsdb_wins.winner = $teamtosort OR sportsdb_wins.loser = $teamtosort)"; 
}

$queryscores .= " ORDER BY wintime ASC";
$resultscores=mysql_query($queryscores);
$numscores=mysql_numrows($resultscores);

while ($scores = mysql_fetch_array($resultscores, MYSQL_ASSOC)) {

$windateheader=$scores['windate'];
$windateformatted=date("l, F j",$windateheader);
$time = date('g:i a',$scores['wintime']);
$time = ($time == "12:00 am")? "<font color='#ff0000'>TBA</font>" : $time;

print "<tr><td class='tbl1'>$windateformatted</td><td class='tbl1'>{$scores['winningteam']}</td>";
print "<td class='tbl1' align='center'><b>{$scores['rf']}</b></td>
<td class='tbl1'>{$scores['losingteam']}</td>";
print "<td class='tbl1' align='center'><b>{$scores['ra']}</b></td>";
if ($show_fields) print "<td class='tbl1'>{$scores['field']}</td>";
if ($scores['winortie'] == 2 || $scores['winortie'] == 5) print " (ff)";
print "</td></tr>\n";
}
echo "</table>\n";
?>

 

I want the table to display all, but (for confid < 11) have open cells for $scores['rf'] and $scores['ra'] fields

Link to comment
https://forums.phpfreaks.com/topic/100575-echo-only-if-id-11/
Share on other sites

here:

 

<?php
print "<table width='100%' class='tbl-border'>\n";
print "<tr><th class='tbl2'>Date</th><th class='tbl2'>Home Team</th><th class='tbl2'>Score</th><th class='tbl2'>Visiting Team</th><th class='tbl2'>Score</th>";
if ($show_fields) print "<th class='tbl2'>Field</th>\n";
$queryscores="SELECT sportsdb_wins.winid, sportsdb_wins.windate, sportsdb_wins.wintime, sportsdb_wins.game_date, sportsdb_wins.game_time, sportsdb_wins.rf, sportsdb_wins.ra, sportsdb_wins.wincomments, sportsdb_wins.field, sportsdb_wins.winortie, sportsdb_teams2.teamname AS winningteam, sportsdb_teams.teamname AS losingteam
FROM sportsdb_wins, sportsdb_teams AS sportsdb_teams2, sportsdb_teams, sportsdb_divs
WHERE sportsdb_teams.teamdiv = sportsdb_divs.divid AND sportsdb_divs.conference = $confid AND sportsdb_teams2.teamid = sportsdb_wins.winner AND sportsdb_teams.teamid = sportsdb_wins.loser AND sportsdb_wins.winortie != 3";

// Sort by team if specified
if (isset($_POST['teamtosort']) && $_POST['teamtosort'] != 'all') {
$teamtosort = intval($_POST['teamtosort']);
$queryscores .= " AND (sportsdb_wins.winner = $teamtosort OR sportsdb_wins.loser = $teamtosort)"; 
}

$queryscores .= " ORDER BY wintime ASC";
$resultscores=mysql_query($queryscores);
$numscores=mysql_numrows($resultscores);

while ($scores = mysql_fetch_array($resultscores, MYSQL_ASSOC)) {
if ($scores['confid'] > '11') {

$windateheader=$scores['windate'];
$windateformatted=date("l, F j",$windateheader);
$time = date('g:i a',$scores['wintime']);
$time = ($time == "12:00 am")? "<font color='#ff0000'>TBA</font>" : $time;

print "<tr><td class='tbl1'>$windateformatted</td><td class='tbl1'>{$scores['winningteam']}</td>";
print "<td class='tbl1' align='center'><b>{$scores['rf']}</b></td>
<td class='tbl1'>{$scores['losingteam']}</td>";
print "<td class='tbl1' align='center'><b>{$scores['ra']}</b></td>";
if ($show_fields) print "<td class='tbl1'>{$scores['field']}</td>";
if ($scores['winortie'] == 2 || $scores['winortie'] == 5) print " (ff)";
print "</td></tr>\n";
}
}
echo "</table>\n";
?>

Link to comment
https://forums.phpfreaks.com/topic/100575-echo-only-if-id-11/#findComment-515191
Share on other sites

For some reason, it must not be recognizing the confid.  For all confid, it displays blank cells for rf and ra.

 

SELECT sportsdb_wins.winid, sportsdb_wins.windate, sportsdb_wins.wintime, sportsdb_wins.game_date, sportsdb_wins.game_time, sportsdb_wins.rf, sportsdb_wins.ra, sportsdb_wins.wincomments, sportsdb_wins.field, sportsdb_wins.winortie, sportsdb_teams2.teamname AS winningteam, sportsdb_teams.teamname AS losingteam

 

maybe I don't understand your query but you never select anything like confid to be in the $rows array and I don't see $confid coming from elsewhere in your code.

Link to comment
https://forums.phpfreaks.com/topic/100575-echo-only-if-id-11/#findComment-515307
Share on other sites

I guess I assumed that since it was part of the WHERE in the query, it was ok.

$queryscores="SELECT sportsdb_wins.winid, sportsdb_wins.windate, sportsdb_wins.wintime, sportsdb_wins.game_date, sportsdb_wins.game_time, sportsdb_wins.rf, sportsdb_wins.ra, sportsdb_wins.wincomments, sportsdb_wins.field, sportsdb_wins.winortie, sportsdb_teams2.teamname AS winningteam, sportsdb_teams.teamname AS losingteam
FROM sportsdb_wins, sportsdb_teams AS sportsdb_teams2, sportsdb_teams, sportsdb_divs
WHERE sportsdb_teams.teamdiv = sportsdb_divs.divid AND sportsdb_divs.conference = $confid AND sportsdb_teams2.teamid = sportsdb_wins.winner AND sportsdb_teams.teamid = sportsdb_wins.loser AND sportsdb_wins.winortie != 3";

 

How do I fix?

Link to comment
https://forums.phpfreaks.com/topic/100575-echo-only-if-id-11/#findComment-515528
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.