Jump to content

Displaying specific date from the database


unknown87

Recommended Posts

Hi,

 

I'm currently in the process of developing a online cricket management game but need some help in displaying the players in the squad page. 

 

I have one table in the database for all the players.  Each player has a team id in the players table.

 

If i logged in and my team id 1, i want all the players relating to team id 1 to display in the squad page. 

 

How would I do this?

 

Thanks in advance

 

Link to comment
Share on other sites

This what you mean?

 

$query = "SELECT player_name FROM players_table WHERE team_id = '1'";
$result = mysql_query($query) or die(mysql_error());
while($row = mysql_fetch_array($result)) {
     echo "Player: " . $row['player_name'] . "
";
}

Link to comment
Share on other sites

Oh sorry, I guess I was confused as to exactly what you wanted.  There may be a better way but this should work.  ***not tested***

 

if(isset($_POST['login_button'])
{
$player_logged_in = $_POST['login_name_field'];
$query = "SELECT team_id FROM players_table WHERE player_name = '$player_logged_in'";
$result = mysql_query($query) or die(mysql_error());
$row = mysql_fetch_array($result)
echo "I am logged in and my team id is: " . $row['team_id'] . "
";

$team_search_id = $row['team_id'];

$query2 = "SELECT player_name FROM players_table WHERE team_id = '$team_search_id";
$result2 = mysql_query($query2) or die(mysql_error());
echo "Here is everyone on my team:";
   while($row2 = mysql_fetch_array($result2)) 
   {
        echo $row2['player_name'] . "
";
   }
}

Link to comment
Share on other sites

 

 if(isset($_POST['login_button'])
{                                                                        <--------------------- Line 29
$player_logged_in = $_POST['login_name_field'];
$query = "SELECT user_id FROM players WHERE player_name = '$player_logged_in'";
$result = mysql_query($query) or die(mysql_error());
$row = mysql_fetch_array($result)
echo "I am logged in and my team id is: " . $row['user_id'] . "<br>";

$team_search_id = $row['user_id'];

$query2 = "SELECT first_name FROM players WHERE team_id = '$team_search_id";
$result2 = mysql_query($query2) or die(mysql_error());
echo "Here is everyone on my team:";
   while($row2 = mysql_fetch_array($result2)) 
   {
        echo $row2['first_name'] . "<br>";
   }
}

 

i'm getting this error:

 

Parse error: syntax error, unexpected '{' in C:\wamp\www\project\senior.php on line 29

Link to comment
Share on other sites

if(isset($_POST['login_button']))
{                                                                        
$player_logged_in = $_POST['login_name_field'];
$query = "SELECT user_id FROM players WHERE player_name = '$player_logged_in'";
$result = mysql_query($query) or die(mysql_error());
$row = mysql_fetch_array($result)
echo "I am logged in and my team id is: " . $row['user_id'] . "<br>"; <----------------------------------- line 34

$team_search_id = $row['user_id'];

$query2 = "SELECT first_name FROM players WHERE team_id = '$team_search_id";
$result2 = mysql_query($query2) or die(mysql_error());
echo "Here is everyone on my team:";
   while($row2 = mysql_fetch_array($result2)) 
   {
        echo $row2['first_name'] . "<br>";
   }
}

 

I got another error:

 

Parse error: syntax error, unexpected T_ECHO in C:\wamp\www\project\senior.php on line 34

Link to comment
Share on other sites

    if(isset($_POST['login_button']))
{
$player_logged_in = $_POST['login_name_field'];
$query = "SELECT user_id FROM players WHERE player_name = '$player_logged_in'";
$result = mysql_query($query) or die(mysql_error());
$row = mysql_fetch_array($result);
echo "I am logged in and my team id is: " . $row['user_id'] . "<br>";

$team_search_id = $row['user_id'];

$query2 = "SELECT first_name FROM players WHERE user_id = '$team_search_id";
$result2 = mysql_query($query2) or die(mysql_error());
echo "Here is everyone on my team:";
   while($row2 = mysql_fetch_array($result2)) 
   {
        echo $row2['first_name'] . "<br>";
   }
}

 

that is the code currently in my squad page

 

I have decided to use the user_id to bring the sqaud details instead of team_id.  Don't know if that makes a difference.

Link to comment
Share on other sites

$user_id=$_SESSION['user_id'];
$query = "SELECT first_name FROM players WHERE user_id = '$user_id'";
$result = mysql_query($query) or die(mysql_error());
while($row = mysql_fetch_array($result)) {
     echo "Player: " . $row['first_name'] . "<br>";
}

 

i managed to get it working by using what was stored in the session.  Is this a good way of doing it?

 

Link to comment
Share on other sites

I though you wanted all the players...?  This only grabs the player that's logged in.  If you want all the players, you have to get the team_id of the player that's logged in and look up the others.

Link to comment
Share on other sites

no I only wanted to display the players that a user has in his team & it's working for me at the moment. 

 

thanks for all your help.

 

OK, glad this is resolved cause I have been confused the whole time  ;D

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.