HELP! Having some trouble with PHP

Discussion in 'PHP' started by shmeeg, Apr 20, 2010.

  1. #1
    Hey.

    I'm currently making a database for a game I've been playing consisting of a few records being kept for teams and individual players. I've been reading up on PHP and it seems to me that it's the easiest to learn and will cater for all my needs.

    The trouble I'm having is as follows:
    1. I'm looking to use the $_GET variable. I'm not sure if it's possible to use multiple conditions with switch but I do know how to use switch for 1 case, and I have been using the following code
    <?php 
    switch($_GET['team'])
    { case "England":
    include("includes/team.php")
    break; }
    ?>
    PHP:
    where "team.php" would include the necessary information to display. I need it to be something along the lines of website.com/statistics/?type=player&player=name for viewing a certain players statistics, and website.com/statistics/?type=team&team=name for viewing a whole team, which would involve two cases.
    I also need this for match reports, where I'm looking to use 3 cases, eg. website.com/statistics/?type=report&tournament=friendly&matchid=1

    2. on team pages, I'm looking to show recent results in the format
    I'm not having any trouble displaying this, but for "Result", I'd like to add a bit of colour, eg. 3-1 for a win, 1-1 would be for a draw, and 1-2 for a loss. Would I have to add the colour when I'm inserting it into the database?

    Furthermore, at the top of a teams page, I would like to add something which involves the teams record, such as
    The only way I know of doing this is
    
    <? $result = mysql_query("SELECT * FROM teams WHERE team='England'") 
    while($rows=mysql_fetch_array($result)){ ?>
    <strong>Record:</strong> played: <? echo $rows['played']; ?>, wins: <? echo $rows['wins']; ?>, losses: <? echo $rows['losses']; ?>, draws: <? echo $rows['draws']; ?>
    
    PHP:
    Would this work correctly? Is this the easiest way to do it? Are there any other methods of doing this?

    3. I'm having trouble with a form I'm using to try to update a players statistics. The form includes: id; name; team; tournament; appearances; goals; assists; total; points per match; man of the match. I'm pretty sure the form has some errors in it, and was wondering if anyone can direct me to a working script that I could use. I've successfully created forms to add to databases, but when I try and use a form that updates, things seem to go pear-shaped.

    Thanks in advance for any help anyone can offer.
     
    Last edited: Apr 20, 2010
    shmeeg, Apr 20, 2010 IP
  2. Nyu

    Nyu Peon

    Messages:
    79
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #2
    1.
    A simple if statement would also do it instead of the switch for only one case ;)

    And what exactly is your problem with more than one case? Take a quick look at PHP.net - Switch where are a few examples how to use switch.

    2.
    How do you get the result for the score? How is it stored in your databse? You can just take a look at how the teams scored and then add something like
    <span style="color:green"><?php echo $score ?></span>
    Code (markup):
    to color your result

    And if you know you will only get one result from your query you can also omitt the while statement but it should also work the way you have it know, or doesn't it?


    Anyway for more detailed help post your code and database structures ;)
     
    Nyu, Apr 20, 2010 IP
  3. shmeeg

    shmeeg Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks for the reply Nyu.

    Referring to #1, the website you directed me to doesn't really explain my problem. I dont think I explained myself very well. I'm trying to use $_GET to display the link "soccerdb.net/statistics/type=player&player=shmeeg". So, in theory, I'd need something like
    switch($1 & $2)
    {
    case "a & b":
    include ("includes/something.php");
    PHP:
    I'm pretty sure this doesn't work though? Rather than 2 cases, I need more than 1 entry in the switch part.

    2. There are multiple matches played, so my PHP code is selecting all entries where the team is involved in that match. It's stored in my database in 1 field, in the format 1-1. If I was to use 2 fields, "home scored" & "away scored", would it be possible to use an if statement, where if "home scored" is greater than "away scored", it will show in green? etc
    If this is possible, could anyone give an example of how I'd do it.

    PS. is <? being depreciated in 5.3? so <?php will have to be used?
     
    Last edited: Apr 20, 2010
    shmeeg, Apr 20, 2010 IP