Dane Posted September 13, 2007 Share Posted September 13, 2007 Hi guys. I have a table which looks like: Below: What i need to do is extract those results from the database so that the results are shown below. Team 1 D D W L L Team 2 D D L W W I have this peice of code that i have done but its not working correctly. <?php $winimage = "<img src=\"images/win.gif\" width=\"13\" height=\"12\"><img src=\"images/spacer.gif\" width=\"1\">"; $drawimage = "<img src=\"images/draw.gif\" width=\"13\" height=\"12\"><img src=\"images/spacer.gif\" width=\"1\">"; $loseimage = "<img src=\"images/lose.gif\" width=\"13\" height=\"12\"><img src=\"images/spacer.gif\" width=\"1\">"; $lresultsQuery = "SELECT * FROM `ladder_results` WHERE `result_teamid` && `result_vsteamid` = '$ladder_teamid' ORDER BY `result_date` ASC"; $lresultsresult = mysql_query($lresultsQuery, $connect) or die(mysql_error()); while ($resultr = mysql_fetch_array($lresultsresult)) { $result_rid = $resultr['result_rid']; $result_date = $resultr['result_date']; $result_teamid = $resultr['result_teamid']; $result_vsteamid = $resultr['result_vsteamid']; $result_for = $resultr['result_for']; $result_against = $resultr['result_against']; $result_rmap = $resultr['result_map']; // Statments To Use Correct Image For Win, Lose or Draw if ($result_for > 15 || $result_for == 1 || $result_for == 0) { echo $winimage; } else if ($result_for < 15) { echo $loseimage; } else if ($result_for == 15) { echo $drawimage; } } ?> That code extracts 5 results from the database. Team 2 D W L Team 1 D W Any ideas on how to get this working correctly? Thanks guys Quote Link to comment https://forums.phpfreaks.com/topic/69177-solved-php-problem/ Share on other sites More sharing options...
adam_ Posted September 13, 2007 Share Posted September 13, 2007 $lresultsQuery = "SELECT * FROM `ladder_results` WHERE `result_teamid` = '$ladder_team_id' OR `result_vsteamid` = '$ladder_team_id' ORDER BY `result_date` ASC"; Give that a try, see if that fixes it, I have a feeling the one you have at the minute is only pulling it if it matches the first team, not if it is the vs team. I dry-ran your code in my head and it behanves as i would expect, give my sql a try see what happens. Dependant on the rest of the code, you might need to swap variables around if it matches the first or the last team in the db. Sorry that sounds confusing, but when you try my sql you might find it shows results the incorrect way around Adam Quote Link to comment https://forums.phpfreaks.com/topic/69177-solved-php-problem/#findComment-347676 Share on other sites More sharing options...
Dane Posted September 13, 2007 Author Share Posted September 13, 2007 Hi That query is pulling the results as such.. Team 2 - D D W W L Team 1 - D D W W L The whole peice of code is <?php require_once('settings.php'); ?> <table width="100%" cellpadding="0" cellspacing="0" border="0"> <tr> <td width="10%" valign="middle">Position</td> <td width="20%" valign="middle">Points</td> <td width="50%" valign="middle">Team Name</td> <td width="20%" valign="middle">Form</td> <td width="10%" valign="middle">Challenge</td> </tr> <?php // Get Teams In Ladder $ladderQuery = "SELECT * FROM `ladder` WHERE `ladder_lid` > '0' ORDER BY `ladder_points` DESC"; $result = mysql_query($ladderQuery, $connect) or die(mysql_error()); $position = 1; while ($ladderc = mysql_fetch_array($result)) { $ladder_lid = $ladderc['ladder_lid']; $ladder_teamid = $ladderc['ladder_teamid']; $ladder_points = $ladderc['ladder_points']; // Get The Team Name $teamnameQuery = "SELECT * FROM `teams` WHERE `team_tid` = $ladder_teamid"; $nameresult = mysql_query($teamnameQuery, $connect) or die(mysql_error()); while ($teamname = mysql_fetch_array($nameresult)) { $team_tid = $teamname['team_tid']; $team_name = $teamname['team_name']; } // End Get The Team Name Query ?> <tr> <td width="10%" valign="middle"><?php echo $position ?></td> <td width="20%" valign="middle"><?php echo $ladder_points ?></td> <td width="50%" valign="middle"><?php echo $team_name ?></td> <td width="20%" valign="middle"> <?php $winimage = "<img src=\"images/win.gif\" width=\"13\" height=\"12\"><img src=\"images/spacer.gif\" width=\"1\">"; $drawimage = "<img src=\"images/draw.gif\" width=\"13\" height=\"12\"><img src=\"images/spacer.gif\" width=\"1\">"; $loseimage = "<img src=\"images/lose.gif\" width=\"13\" height=\"12\"><img src=\"images/spacer.gif\" width=\"1\">"; $lresultsQuery = "SELECT * FROM `ladder_results` WHERE `result_teamid` = '$ladder_teamid' OR `result_vsteamid` = '$ladder_teamid' ORDER BY `result_date` ASC"; $lresultsresult = mysql_query($lresultsQuery, $connect) or die(mysql_error()); while ($resultr = mysql_fetch_array($lresultsresult)) { $result_rid = $resultr['result_rid']; $result_date = $resultr['result_date']; $result_teamid = $resultr['result_teamid']; $result_vsteamid = $resultr['result_vsteamid']; $result_for = $resultr['result_for']; $result_against = $resultr['result_against']; $result_rmap = $resultr['result_map']; // Statments To Use Correct Image For Win, Lose or Draw if ($result_for > 15 || $result_for == 1 || $result_for == 0) { echo $winimage; } else if ($result_for < 15) { echo $loseimage; } else if ($result_for == 15) { echo $drawimage; } } ?> </td> <td width="10%" valign="middle">Yes</td> </tr> <?php $position++; } // End Teams In Ladder Query ?> </table> <table width="100%" cellpadding="0" cellspacing="0" border="0"> <tr> <td width="100%" valign="middle" align="right"> <select size=1 name="game"> <? $gameQuery=mysql_query("SELECT * FROM `ladder_games` WHERE `active`='1' ORDER BY `name` ASC"); while($gi=mysql_fetch_array($gameQuery)) { if($gi['id']==$i['game']) { $sel="selected"; } else { $sel=""; } echo "<option value=\"".$gi['id']."\" $sel>".stripslashes($gi['name'])."</option>"; } ?> </select> </td> </tr> </table> Quote Link to comment https://forums.phpfreaks.com/topic/69177-solved-php-problem/#findComment-347680 Share on other sites More sharing options...
adam_ Posted September 13, 2007 Share Posted September 13, 2007 I took the liberty of pastebin'ing the code for some syntax highlighting and a changelog http://pastebin.com/pastebin.php?diff=d6a44acae I added 5 lines in there (around line 71), by adding that code see what happens. (it is the code i meant when i said about swapping variables. I didnt check the $temp wasn't already in use so maybe you need to change the variable name Quote Link to comment https://forums.phpfreaks.com/topic/69177-solved-php-problem/#findComment-347692 Share on other sites More sharing options...
Dane Posted September 13, 2007 Author Share Posted September 13, 2007 Thanks a lot adam. You've been a lot of help, that worked perfect. Thanks again mate. Quote Link to comment https://forums.phpfreaks.com/topic/69177-solved-php-problem/#findComment-347694 Share on other sites More sharing options...
adam_ Posted September 13, 2007 Share Posted September 13, 2007 No problem. Glad it worked for you. Quote Link to comment https://forums.phpfreaks.com/topic/69177-solved-php-problem/#findComment-347700 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.