kemper Posted April 11, 2008 Share Posted April 11, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/100575-echo-only-if-id-11/ Share on other sites More sharing options...
JSHINER Posted April 11, 2008 Share Posted April 11, 2008 Try replacing: print "<td class='tbl1' align='center'><b>{$scores['ra']}</b></td>"; With: if($scores['confid'] > 11) print "<td class='tbl1' align='center'><b>{$scores['ra']}</b></td>"; Quote Link to comment https://forums.phpfreaks.com/topic/100575-echo-only-if-id-11/#findComment-514994 Share on other sites More sharing options...
kemper Posted April 11, 2008 Author Share Posted April 11, 2008 No go. That took away the <td> on all confid and skewed the whole table. Quote Link to comment https://forums.phpfreaks.com/topic/100575-echo-only-if-id-11/#findComment-515186 Share on other sites More sharing options...
PC Nerd Posted April 11, 2008 Share Posted April 11, 2008 use the above condition and the print ( i use echo) in the following format: if(<condition>) { echo nums that are correct } else { echo empty td } Quote Link to comment https://forums.phpfreaks.com/topic/100575-echo-only-if-id-11/#findComment-515190 Share on other sites More sharing options...
unidox Posted April 11, 2008 Share Posted April 11, 2008 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"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/100575-echo-only-if-id-11/#findComment-515191 Share on other sites More sharing options...
kemper Posted April 11, 2008 Author Share Posted April 11, 2008 The only echo result is the header row of the table and that is for all confid. Basically, I get: Date Home Team Score Visiting Team Score Field No result rows at all. Quote Link to comment https://forums.phpfreaks.com/topic/100575-echo-only-if-id-11/#findComment-515193 Share on other sites More sharing options...
JSHINER Posted April 12, 2008 Share Posted April 12, 2008 Sorry yea forgot the else... if($scores['confid'] > 11) print "<td class='tbl1' align='center'><b>{$scores['ra']}</b></td>"; else print "<td class='tbl1' align='center'><b></b></td>"; Quote Link to comment https://forums.phpfreaks.com/topic/100575-echo-only-if-id-11/#findComment-515290 Share on other sites More sharing options...
kemper Posted April 12, 2008 Author Share Posted April 12, 2008 For some reason, it must not be recognizing the confid. For all confid, it displays blank cells for rf and ra. Quote Link to comment https://forums.phpfreaks.com/topic/100575-echo-only-if-id-11/#findComment-515294 Share on other sites More sharing options...
AndyB Posted April 12, 2008 Share Posted April 12, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/100575-echo-only-if-id-11/#findComment-515307 Share on other sites More sharing options...
kemper Posted April 12, 2008 Author Share Posted April 12, 2008 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? Quote Link to comment https://forums.phpfreaks.com/topic/100575-echo-only-if-id-11/#findComment-515528 Share on other sites More sharing options...
kemper Posted April 15, 2008 Author Share Posted April 15, 2008 Bueller?! Quote Link to comment https://forums.phpfreaks.com/topic/100575-echo-only-if-id-11/#findComment-517361 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.