Jump to content


Photo

Small help with displaying certain rows


  • Please log in to reply
2 replies to this topic

#1 Mutley

Mutley
  • Members
  • PipPipPip
  • Advanced Member
  • 765 posts

Posted 02 September 2006 - 09:38 PM

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:
<?php


require_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;
			}
		}
	}
?>

So for example I would want, Next Match for Team 1 only, after the next match for every team together.
~ Mutley.

#2 Mutley

Mutley
  • Members
  • PipPipPip
  • Advanced Member
  • 765 posts

Posted 02 September 2006 - 10:19 PM

Same sort of problem here:

(PROBLEM #2)
<?php
require_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";
}
?>

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.
~ Mutley.

#3 contrabandheart

contrabandheart
  • New Members
  • Pip
  • Newbie
  • 7 posts

Posted 02 September 2006 - 10:26 PM

Hey Mutley.

If I understand your problem at all, it should be able to be fixed by selecting only DISTINCT entries.

i.e., the query below would give you all the rows.
mysql_query("SELECT * FROM `table`");
With values named "1", "2", and "3", if each was in the table three times, it would get
1
1
1
2
2
2
3
3
3

THIS query would only select entries in which the selected row was unique:
mysql_query("SELECT DISTINCT entry FROM table");
This would give you:
1
2
3

You are the weakest Uniform Resource Locator... Goodbye.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users