Jump to content

Archived

This topic is now archived and is closed to further replies.

Mutley

Small help with displaying certain rows

Recommended Posts

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]<?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;
}
}
}
?>[/code]

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

Share this post


Link to post
Share on other sites
Same sort of problem here:

(PROBLEM #2)
[code]<?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";
}
?>[/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.

Share this post


Link to post
Share on other sites
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]
1
1
1
2
2
2
3
3
3
[/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]
1
2
3
[/code]

Share this post


Link to post
Share on other sites

×

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.