Jump to content

Recommended Posts

ya, its me again... :(

 

basically, im using $_GET so that players can bookmark pages for easy access, for example, stats.php?type=player&player=shmeeg (where obviously it only displays my statistics)

 

however, my code works up to  a point. im using a switch case for type=team&team=$team

 

heres the code (it's working fine)

<?php
	$team = $_GET['team'];
	 switch ($team){
case "$team":
$result = mysql_query("SELECT * FROM players WHERE team='$team' ORDER BY total DESC") or die(mysql_error());  
echo "<table>";
echo "<tr> <th>player name</th>  <th>appearances</th>  <th>goals</th>  <th>assists</th>  <th>total</th>  <th>points/match</th>  <th># motm</th> </tr>";
while($row = mysql_fetch_array( $result )) 
{   echo "<tr><td>"; 
echo $row['name'];
echo "</td><td><center>"; 
echo $row['apps'];
echo "</center></td><td><center>";
echo $row['goals'];
echo "</center></td><td><center>";
echo $row['assists'];
echo "</center></td><td><center>";
echo $row['total'];
echo "</center></td><td><center>";
echo $row['ppm'];
echo "</center></td><td><center>";
echo $row['motm'];
echo "</center></td></tr>"; 
}   echo "</table>";
	break; 
	} ?>

 

the next step would be to

$player = $_GET['player'];
	 switch ($player){

firstly is this even possible?:D

 

would i need to use another method or would this actually work?

Link to comment
https://forums.phpfreaks.com/topic/204015-switch-case-with-2-switches/
Share on other sites

i now have a whole host of errors...i'm a little bit lost

 

here's the whole piece of code:

<?php
	$team = $_GET['team'];

	 switch ($team){
case "$team":
$result = mysql_query("SELECT * FROM players WHERE team='$team' ORDER BY total DESC") or die(mysql_error());  
echo "<table>";
echo "<tr> <th>player name</th>  <th>appearances</th>  <th>goals</th>  <th>assists</th>  <th>total</th>  <th>points/match</th>  <th># motm</th> </tr>";
while($row = mysql_fetch_array( $result )) 
{   echo "<tr><td>"; 
echo $row['name'];
echo "</td><td><center>"; 
echo $row['apps'];
echo "</center></td><td><center>";
echo $row['goals'];
echo "</center></td><td><center>";
echo $row['assists'];
echo "</center></td><td><center>";
echo $row['total'];
echo "</center></td><td><center>";
echo $row['ppm'];
echo "</center></td><td><center>";
echo $row['motm'];
echo "</center></td></tr>"; 
}   echo "</table>";
	break;  }

	$player = $_GET['name'];
switch ($player){	
case "$player":
$result2 = mysql_query("SELECT * FROM players WHERE name='$player'") or die(mysql_error());  
echo "name:"; echo $_GET["name"]; echo "<br />";
echo "nation:"; echo $_GET["team"]; echo "<br />";
	break; 
	} ?>

 

i really am lost :(

<?php

$team = $_GET['team'];

 

switch ($team){

case "$team":

$result = mysql_query("SELECT * FROM players WHERE team='$team' ORDER BY total DESC") or die(mysql_error()); 

echo "<table>";

echo "<tr> <th>player name</th>  <th>appearances</th>  <th>goals</th>  <th>assists</th>  <th>total</th>  <th>points/match</th>  <th># motm</th> </tr>";

while($row = mysql_fetch_array( $result ))

{  echo "<tr><td>";

echo $row['name'];

echo "</td><td><center>";

echo $row['apps'];

echo "</center></td><td><center>";

echo $row['goals'];

echo "</center></td><td><center>";

echo $row['assists'];

echo "</center></td><td><center>";

echo $row['total'];

echo "</center></td><td><center>";

echo $row['ppm'];

echo "</center></td><td><center>";

echo $row['motm'];

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

}  echo "</table>";

break; 

 

$player = $_GET['name'];

switch ($player){

case "$player":

$result2 = mysql_query("SELECT * FROM players WHERE name='$player'") or die(mysql_error()); 

echo "name:"; echo $_GET["name"]; echo "<br />";

echo "nation:"; echo $_GET["team"]; echo "<br />";

break;

} } ?>[/code]try that

basically, what I'm trying to do is make it so that the URL reads /stats.php?type=team&team=UK or /stats.php?type=player&player=shmeeg

 

depending on "type", different information will be displayed.

 

if type=player, then player statistics will be displayed, eg.

name: shmeeg

nation: UK

position: defender

 

tournament apps goals assists total ppm motm

world cup      3      1        6      7    7/3    2

 

matches

time/date home away result stats

time/date  UK    FI      1-2  0+1  match report

 

if type=team, then team stats will be displayed eg.

nation: UK

statistics: played 5, won 3, lost 1, drawn 1

players: defenders: list of defenders from team selection

            midfielders: list of midfielders from team selection

            attackers: list of attackers from team selection

 

tournament played goals for goals against +/-

world cup      3          11            4          +7

friendly          2          6              1          +6

 

recent matches

time/date tournament home away result

time/date  world cup    UK    FI      1-2      match report

Your code is funky!

Ok lets break this done a bit for you

 


$team = $_GET['team']; //so $team will be a value like player 
   
switch ($team){

   //case "$team": // This is wrong - you are looking for a value here - not a variable

case "player":
//So if the URL variable is player you will output this code (I havent checked it!)

   $result = mysql_query("SELECT * FROM players WHERE team='$team' ORDER BY total DESC") or die(mysql_error()); 
   echo "<table>";
   echo "<tr> <th>player name</th>  <th>appearances</th>  <th>goals</th>  <th>assists</th>  <th>total</th>  <th>points/match</th>  <th># motm</th> </tr>";
while($row = mysql_fetch_array( $result ))
{   echo "<tr><td>";
   echo $row['name'];
   echo "</td><td><center>";
   echo $row['apps'];
   echo "</center></td><td><center>";
   echo $row['goals'];
   echo "</center></td><td><center>";
   echo $row['assists'];
   echo "</center></td><td><center>";
   echo $row['total'];
   echo "</center></td><td><center>";
   echo $row['ppm'];
   echo "</center></td><td><center>";
   echo $row['motm'];
   echo "</center></td></tr>";
}   echo "</table>";
echo "</table>";     
break; 
      
// Ok now second case - I used player2 as an example


   case "player2":

   $result2 = mysql_query("SELECT * FROM players WHERE name='$player'") or die(mysql_error()); 
   echo "name:"; echo $_GET["name"]; echo "<br />";
   echo "nation:"; echo $_GET["team"]; echo "<br />";
      break;

//dont forget a default case incase nothing matches
default:
       echo "this is the default option";
      }

//ending the switch

} ?>

I hope that helps!

I dont need two cases. I'm using 1 generic case. $_GET is defining what the case is. So if I search for /stats.php?type=team&team=UK, it will display all team statistics for the team UK, and the same for any other team. What I need to do now is to be able to change type to player, and for it to do the same for the player chosen.

The Case statement will allow you to get the Team for example, then using mysql you can get the player - is that what you mean? You can also call a function within the case - so pass a parameter for the player to output the relevant stats accourding to URL parameter.

Funkeh!

 

$type = $_GET['type'];
if ('team' == $type) {
  $team = $_GET['team'];
  $stats = get_team_stats($team);
  display_team_stats($stats);
} elseif ('player' == $type) {
  $player = $_GET['player'];
  $stats = get_player_stats($player);
  display_player_stats($stats);
} else {  
  die('You can only look up stats for a team or a player');
}

function get_team_stats($team_name) {
  //somehow get the stats, make sure you use mysql_real_escape_string() on the $team_name, otherwise people can erase all your data, reference http://en.wikipedia.org/wiki/SQL_injection
}

function get_player_stats($player_name) {
  //get the stats for the player, again use mysql_real_escape_string() on $player_name for same reason as above
}

function display_team_stats($stats) {
  //turn the stats array into HTML
}

function display_player_stats($stats) {
  //turn the stats array into HTML
}

this is confusing me a lot

 

to clear it up, I could post some examples of what I'm trying to do

 

http://ohl-liiga.net/index.php?sivu=joukkueet&id=32 (sivu=page and joukkueet=team)

http://www.kiekkoliiga.net/tilastot/?tilasto=pelaaja&id=934 (tilastot=statistics, pelaaja=player)

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.