Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!--
- This example uses jquery to hide/show the teams players without refreshing the page.
- All the data is retreived at the 1st execution and is then shown/hidden by clicking on the team name.
- Would probably need some formating etc to make it look good :D
- -->
- <?php
- //Connect to your database
- $sql_server='localhost';
- $sql_db='teams';
- $sql_user='root';
- $sql_pass='23011809';
- mysql_connect($sql_server,$sql_user,$sql_pass);
- mysql_select_db($sql_db);
- ?>
- <html>
- <head>
- <title>Teams</title>
- <script src="jquery-1.4.4.js"></script>
- </head>
- <body>
- <?php
- //Select every row from teams
- $sql = mysql_query("
- SELECT *
- FROM teams
- ") or die(mysql_error());
- //Loop through each row
- while($row = mysql_fetch_array($sql))
- {
- ?>
- <!--Make a jscript for toggling the players -->
- <script>
- $(document).ready(function(){
- $('.<?php echo $row['team']; ?>').click(function(){
- $('.<?php echo $row['team']; ?>_players').toggle();
- })
- });
- </script>
- <?php
- //Echo the team name
- echo '<a class="'.$row['team'].'">'.$row['team'].'</a><br />';
- //Echo the players (Will be hidden on page load)
- echo '<p class="'.$row['team'].'_players" style="display:none;">';
- //Turn the cvs from db into an array.
- $players=explode(',',$row['players']);
- //Because players are stored as a cvs in database, loop through each player from the new array.
- foreach($players as $player) echo $player .'<br />';
- echo '</p>';
- }
- ?>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment