Jump to content

MYSQL outputing help


Aravinthan
 Share

Recommended Posts

Hi,

I am making a personal site about me and I wanted to show my teams last 5 games scores and the scorers. So I made a DB:

Gameid

gf

ga

winner

lname

goals

assists

points

And now I am outputting it:

<?php

$link = mysql_connect ("localhost", "user", "pass")

or die("mysql_error()");

mysql_select_db ("stmaxel_stats", $link);

$result = mysql_query("SELECT * FROM `games` ORDER BY gameid DESC LIMIT 1 ",$link);

while($row = mysql_fetch_array($result))

  {

  echo "Game Number: " .$row['gameid']. "</br>";

  echo "A " .$row['gf']. "-" .$row['ga']. " " .$row['winner']. "<br/>";

  echo "Scorers:<br/>";

                                                echo "<center><table border='1' width='100%' bordercolor='#413326'>

  <tr>

  <th align='center' BGCOLOR='#413326'><FONT COLOR='#FFFFFF' size='3'>Lastname</font>

  <th align='center' BGCOLOR='#413326'><FONT COLOR='#FFFFFF' size='3'>Goals</font>

  <th align='center' BGCOLOR='#413326'><FONT COLOR='#FFFFFF' size='3'>Assists</font>

  <th align='center' BGCOLOR='#413326'><FONT COLOR='#FFFFFF' size='3'>Points</font>";

                                                echo "</tr>

                                                      <tr>";

                                                echo "<td>" . $row['lname'] . "</td>";

echo "<td width='7%'>" . $row['lnameg'] . "</td>";

echo "<td width='7%'>" . $row['lnamea'] . "</td>";

                                                echo "<td width='7%'>" . $row['lnamep'] . "</td>";

                                                echo "</tr></table></center>";

                                                }

?>

The thing is that it outputs the same game 2 times. I just saw my mistake, I enter the different players who had points in this game. But differently. So there is more than 1 entry for the same game. And when I try to output it, it shows in 2 different tables. Is there any way that I can show it in only 1 table?

I am not sure if I am clear, if you dont understand let me know and I'll try to clear myself.

 

THanks for your help and time,

Ara

Link to comment
Share on other sites

Ok, so I changed my tables:

games:

gameid, ga, gf and winner

players:

gameid, goals, assists and points.

And this is my coding:

result = mysql_query("SELECT * FROM games, players WHERE games.gameid = players.gameid  ORDER BY gameid DESC LIMIT 5 ",$link);
										while($row = mysql_fetch_array($result))
										  {
										  	echo "Game Number: " .$row['gameid']. "</br>";
										  	echo "A " .$row['gf']. "-" .$row['ga']. " " .$row['winner']. "<br/>";
										  	echo "Scorers:<br/>";
                                                echo "<center><table border='1' width='100%' bordercolor='#413326'>
												  <tr>
												  <th align='center' BGCOLOR='#413326'><FONT COLOR='#FFFFFF' size='3'>Lastname</font>
												  <th align='center' BGCOLOR='#413326'><FONT COLOR='#FFFFFF' size='3'>Goals</font>
												  <th align='center' BGCOLOR='#413326'><FONT COLOR='#FFFFFF' size='3'>Assists</font>
												  <th align='center' BGCOLOR='#413326'><FONT COLOR='#FFFFFF' size='3'>Points</font>";
                                                echo "</tr>
                                                      <tr>";
                                                echo "<td>" . $row['lname'] . "</td>";
											echo "<td width='7%'>" . $row['lnameg'] . "</td>";
											echo "<td width='7%'>" . $row['lnamea'] . "</td>";
                                                echo "<td width='7%'>" . $row['lnamep'] . "</td>";
                                                echo "</tr></table></center>";
                                                }

 

But there is no data that is getting displayed....

 

Thanks for your help,

Ara

Link to comment
Share on other sites

I've gotten this to work with a similar database. You may be able to modify where needed.

$result = mysql_query("SELECT * FROM games
ORDER BY games.game_id DESC LIMIT 5",$link);
while($row = mysql_fetch_assoc($result))
{
$result2 = mysql_query("SELECT * FROM players
WHERE game_id='{$row['game_id']}'",$link);
$nrows=mysql_num_rows($result2);
echo "Game Number: " .$row['game_id']. "</br>";
echo "A " .$row['gf']. "-" .$row['ga']. "-"  .$row['winner']. "<br/>";
echo "Scorers:<br/>";
echo "<center><table border='1' width='100%' bordercolor='#413326'>
<tr>
<th align='center' BGCOLOR='#413326'><FONT COLOR='#FFFFFF' size='3'>Lastname</font>
<th align='center' BGCOLOR='#413326'><FONT COLOR='#FFFFFF' size='3'>Goals</font>
<th align='center' BGCOLOR='#413326'><FONT COLOR='#FFFFFF' size='3'>Assists</font>
<th align='center' BGCOLOR='#413326'><FONT COLOR='#FFFFFF' size='3'>Points</font></tr>";
if($nrows >0)
{
while($row2 = mysql_fetch_assoc($result2))
{
echo "<tr>";
echo "<td width='7%'>" .$row2['lname']. "</td>";
echo "<td width='7%'>" .$row2['lnameg']. "</td>";
echo "<td width='7%'>" .$row2['lnamea']. "</td>";
echo "<td width='7%'>" .$row2['lnamep']. "</td>";
echo "</tr>";
}
echo "</table></center>";
}
}

Link to comment
Share on other sites

This thread is more than a year old.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...

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.