daveh24706 Posted May 10, 2010 Share Posted May 10, 2010 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 https://forums.phpfreaks.com/topic/201310-php-mysql-league-table-help/ Share on other sites More sharing options...
Psycho Posted May 10, 2010 Share Posted May 10, 2010 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 https://forums.phpfreaks.com/topic/201310-php-mysql-league-table-help/#findComment-1056176 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.