unknown87 Posted October 29, 2008 Share Posted October 29, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/130637-displaying-specific-date-from-the-database/ Share on other sites More sharing options...
Maq Posted October 29, 2008 Share Posted October 29, 2008 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'] . " "; } Quote Link to comment https://forums.phpfreaks.com/topic/130637-displaying-specific-date-from-the-database/#findComment-677796 Share on other sites More sharing options...
unknown87 Posted October 29, 2008 Author Share Posted October 29, 2008 yes but how do i make the code autmatically recognise which team id the user has logged in with? Quote Link to comment https://forums.phpfreaks.com/topic/130637-displaying-specific-date-from-the-database/#findComment-677814 Share on other sites More sharing options...
kenshintomoe225 Posted October 29, 2008 Share Posted October 29, 2008 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? Quote Link to comment https://forums.phpfreaks.com/topic/130637-displaying-specific-date-from-the-database/#findComment-677823 Share on other sites More sharing options...
Maq Posted October 29, 2008 Share Posted October 29, 2008 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'] . " "; } } Quote Link to comment https://forums.phpfreaks.com/topic/130637-displaying-specific-date-from-the-database/#findComment-677831 Share on other sites More sharing options...
unknown87 Posted October 29, 2008 Author Share Posted October 29, 2008 thank you very much Quote Link to comment https://forums.phpfreaks.com/topic/130637-displaying-specific-date-from-the-database/#findComment-677856 Share on other sites More sharing options...
Maq Posted October 30, 2008 Share Posted October 30, 2008 thank you very much Does this solve your problem? Quote Link to comment https://forums.phpfreaks.com/topic/130637-displaying-specific-date-from-the-database/#findComment-678479 Share on other sites More sharing options...
unknown87 Posted October 30, 2008 Author Share Posted October 30, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/130637-displaying-specific-date-from-the-database/#findComment-678792 Share on other sites More sharing options...
MasterACE14 Posted October 30, 2008 Share Posted October 30, 2008 post your whole code. the error isn't on line 29. PHP lied! EDIT. this line... if(isset($_POST['login_button']) missing a parenthesis. if(isset($_POST['login_button'])) Quote Link to comment https://forums.phpfreaks.com/topic/130637-displaying-specific-date-from-the-database/#findComment-678802 Share on other sites More sharing options...
unknown87 Posted October 30, 2008 Author Share Posted October 30, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/130637-displaying-specific-date-from-the-database/#findComment-678864 Share on other sites More sharing options...
MasterACE14 Posted October 31, 2008 Share Posted October 31, 2008 missing the semi colon on this line.... $row = mysql_fetch_array($result) replace with this... $row = mysql_fetch_array($result); Quote Link to comment https://forums.phpfreaks.com/topic/130637-displaying-specific-date-from-the-database/#findComment-679071 Share on other sites More sharing options...
unknown87 Posted October 31, 2008 Author Share Posted October 31, 2008 thanks - all the errors are gone but nothing coming up on the squad page. any ideas why? Quote Link to comment https://forums.phpfreaks.com/topic/130637-displaying-specific-date-from-the-database/#findComment-679583 Share on other sites More sharing options...
unknown87 Posted October 31, 2008 Author Share Posted October 31, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/130637-displaying-specific-date-from-the-database/#findComment-679598 Share on other sites More sharing options...
unknown87 Posted October 31, 2008 Author Share Posted October 31, 2008 $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? Quote Link to comment https://forums.phpfreaks.com/topic/130637-displaying-specific-date-from-the-database/#findComment-679724 Share on other sites More sharing options...
Maq Posted November 3, 2008 Share Posted November 3, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/130637-displaying-specific-date-from-the-database/#findComment-681219 Share on other sites More sharing options...
unknown87 Posted November 4, 2008 Author Share Posted November 4, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/130637-displaying-specific-date-from-the-database/#findComment-682253 Share on other sites More sharing options...
Maq Posted November 4, 2008 Share Posted November 4, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/130637-displaying-specific-date-from-the-database/#findComment-682310 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.