Jump to content

php mysql league table help


daveh24706

Recommended Posts

hello,

 

Im trying to create a league table where a user selects a year ie (2009-2010) and the league table is printed out for than year. However the problem im having is i can get it to print out table but only one team at a time and i cant get it to print out the full table. If anyone can tell me how i can retrieve all teams and display on a databases it would be great.

 

<?php
$q=$_GET["q"];

$con = mysql_connect('localhost', 'root', '');
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("lfc", $con);

$sql="SELECT * FROM rankings WHERE id = '".$q."'";
$result = mysql_query($sql);

echo "<table border='8'>
</tr>
<th>Position</th>
<th>Team Name</th>
<th>Played</th>
<th>Won</th>
<th>Drew</th>
<th>Lost</th>
<th>For</th>
<th>Against</th>
<th>GoalD</th>
<th>Pts</th>
</tr>";

while($row = mysql_fetch_array($result))
  {
  echo "<tr>";
  echo "<td>" . $row['id'] . "</td>";
  echo "<td>" . $row['Name']. "</td>";
  echo "<td>" . $row['P'] . "</td>";
  echo "<td>" . $row['W'] . "</td>";
  echo "<td>" . $row['D'] . "</td>";
  echo "<td>" . $row['L'] . "</td>";
  echo "<td>" . $row['F'] . "</td>";
  echo "<td>" . $row['A'] . "</td>";
  echo "<td>" . $row['GC'] . "</td>";
  echo "<td>" . $row['Pts'] . "</td>";
  
  echo "</tr>";
  }
echo "</table>";
   
mysql_close($con);
?> 

 

html page

<select name="users" onchange="showUser(this.value)">
<option value="">Select Season Year:</option>
<option value="1">2009/2010 Season</option>

 

the structure on my database is id (which increments) then teamname, pts, wins etc

 

anyone know how to print all teams/ids

Link to comment
Share on other sites

I think your query is messed up. The select list is to select the season (named 'users'), but you use the post value 'q' as the ID from the rankings table. I suspect the ID is a unique identifier for each team? Can't be sure without knowing your database structure, but I think you should be using the season value something like this:

 

$season_id = mysql_real_escape_string($_POST['users']);
$sql="SELECT * FROM rankings WHERE season_id = '{$season_id}'";

 

Also, you should fix the opening TR tag for your headings.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.

×
×
  • 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.