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

 

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'] . "
";
}

not quite sure what you're asking here with your second post.  After a player logs in, pull the team id out? 

SELECT player_name, team_id FROM players_table WHERE player_id='some_variable_you_set_via_form'

 

is that what you're looking for?

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'] . "
";
   }
}

 

 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

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

    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.

$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?

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.