Mutley Posted September 2, 2006 Share Posted September 2, 2006 I have a script that displays a latest "score" by the date and is limited to one, the problem I have is I want to do a latest score for all teams but then a latest score for 4 other teams.The problem I'm having is how do I display the next score by date JUST for that team and have my display score for all the teams together aswell?Here is my script:[code]<?phprequire_once("connection.php");$teamnames = array('1st Team','2nd Team','3rd Team','4th Team','u7s Team','u8s team','u9s team','u10s team','u11s team','u12s team','u13s team','u14s team','u15s team','u17s Dev','u19s Dev');$query = "SELECT team_id, DATE_FORMAT(date,'%d-%m-%Y') AS dstamp, home, away FROM scores ORDER BY date LIMIT 1";$result = mysql_query($query);if(mysql_num_rows($result)!=0) { while(list($team_id, $dstamp, $home, $away) = mysql_fetch_row($result)) { ?> Next match on: </b><br /> <?=$dstamp?> <br /><b> For: </b><br /><?php $str = $teamnames[$team_id]; $str = ucwords($str); echo $str; ?> <br /><b> Against: </b><br /><?php if($home == York) { echo $away; } else { echo $home; } } }?>[/code]So for example I would want, Next Match for Team 1 only, after the next match for every team together. Quote Link to comment Share on other sites More sharing options...
Mutley Posted September 2, 2006 Author Share Posted September 2, 2006 Same sort of problem here:(PROBLEM #2)[code]<?phprequire_once("connection.php"); $sql = "SELECT team_id, score_id, DATE_FORMAT(date,'%d-%m-%Y') AS dstamp, home, away, scorehome, scoreaway, description "; $sql .= "FROM scores "; $sql .= "ORDER BY date "; $sql .= "LIMIT team_id BY 1"; $result = mysql_query($sql); if(mysql_num_rows($result)!=0) { while(list($team_id, $score_id, $dstamp, $home, $away, $scorehome, $scoreaway, $description) = mysql_fetch_row($result)) { ?> Team ID: <?=$team_id?><br />Score ID: <?=$score_id?><br />Date: <?=$dstamp?><br />Home: <?=$home?><br/>Away: <?=$away?><br />Score H: <?=$scorehome?><br />Score A: <?=$scoreaway?><br />Description: <?=$description?><br /><br /><?php} } else { echo "No scores were found";}?>[/code]I want it to limit 1 score (all the rows/entries for that team_id) per a team and only allow 1 of each team to be displayed (so Team 1 does not appear more than once for example), instead of listing everything in my database. Quote Link to comment Share on other sites More sharing options...
contrabandheart Posted September 2, 2006 Share Posted September 2, 2006 Hey Mutley.If I understand your problem at all, it should be able to be fixed by selecting only [i]DISTINCT[/i] entries.i.e., the query below would give you all the rows.[code]mysql_query("SELECT * FROM `table`");[/code]With values named "1", "2", and "3", if each was in the table three times, it would get[code]111222333[/code]THIS query would only select entries in which the selected row was unique:[code]mysql_query("SELECT DISTINCT entry FROM table");[/code]This would give you:[code]123[/code] Quote Link to comment 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.