pmg206 Posted October 8, 2009 Share Posted October 8, 2009 The setup is pretty generic, but this one is kicking my butt. Using a PHP page (Yahoo hosting, which is still on MySQL 4.1.14), the goal is to provide users a dropdown list of values that are limited to only what the page user, per their login credentials, should see. (The project is sort of like a soccer league page, but we only want the coach to see members of his/her team in a dropdown list, even though all league players are in the single table.) I figured this would be a no-brainer, based on the login ID and passing the login username/cookie into the query, but I figured wrong. (In this way, the page would then only show them the values that were associated with their team, and pop them into a dropdown list.) But how the cookie needs to be formatted is where I crumble, as it were... The ideal sort of query, which sort of puts the web page into blank-ness, is similar to: $query_team_list = "SELECT * FROM tbl_players WHERE status = 'A' and team_id = <?php echo $HTTP_COOKIE_VARS['cookie4team']; ?> ORDER BY fname ASC"; The team ID is pulled from the cookie created at login, i.e. 101 (always an integer, not the most elegant approach, but that's another issue). If we go with this code, stuff comes back (obviously), but it's retrieving everyone. Not stellar to scroll through dozens of names to find your folks: $query_team_list = "SELECT * FROM tbl_players WHERE status = 'A' and team_id > 1 ORDER BY fname ASC"; Which suggests either I can't do this -- seems unlikely -- or my the means/format of inserting the cookie into the query itself is a no-no. Thoughts? Thanks in advance! Quote Link to comment Share on other sites More sharing options...
johnsmith153 Posted October 8, 2009 Share Posted October 8, 2009 $query_team_list = "SELECT * FROM tbl_players WHERE status = 'A' and team_id = ".$HTTP_COOKIE_VARS['cookie4team']." ORDER BY fname ASC"; Quote Link to comment Share on other sites More sharing options...
manwhoeatsrats Posted October 8, 2009 Share Posted October 8, 2009 $query_team_list = "SELECT * FROM tbl_players WHERE status = 'A' and team_id = ".$HTTP_COOKIE_VARS['cookie4team']." ORDER BY fname ASC"; Should work. I will bet what you were getting is a parsing error. That is because you were already in php when you tried to start php again with the <?php echo $HTTP_COOKIE_VARS['cookie4team']; ?>. also when you are adding a variable to another variable it doe not have to be echoed. $all_vars = $var1 . $var2 ; Not $all_vars = echo $var1 . echo $var2; Hope this was helpful Quote Link to comment Share on other sites More sharing options...
pmg206 Posted October 9, 2009 Author Share Posted October 9, 2009 Thanks to you both -- that was it. Figured it was how I was plugging it on (or rather, Dreamweaver suggested it be used, good grief). Thanks again! Quote Link to comment 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.