padams Posted August 19, 2007 Share Posted August 19, 2007 I'm trying to use the SQL IN command when I query my mySQL database, but the value I am sending in it is an array, created when users selected multiple options in a list. I've been looking around and have seen a few possible solutions involving SQL, but I'm relatively new to PHP and SQL and am not quite sure how to resolve this. Any ideas? matchTeam is the array: $players = $_POST['matchTeam']; $playerGames = "SELECT * FROM players WHERE playerID IN ($players)"; $playerGames_query = mysql_query($playerGames) or die(mysql_error()); $rsPlayerGames = mysql_fetch_assoc($playerGames_query); Quote Link to comment https://forums.phpfreaks.com/topic/65669-including-array-in-sql-in/ Share on other sites More sharing options...
sasa Posted August 19, 2007 Share Posted August 19, 2007 $playerGames = "SELECT * FROM players WHERE playerID IN (". implode(", ",$players). ")"; Quote Link to comment https://forums.phpfreaks.com/topic/65669-including-array-in-sql-in/#findComment-327960 Share on other sites More sharing options...
padams Posted August 20, 2007 Author Share Posted August 20, 2007 Thanks, but that just returned information for the first item selected only. It also repeated it 15 times, although I only selected a few items. Any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/65669-including-array-in-sql-in/#findComment-328622 Share on other sites More sharing options...
vijayfreaks Posted August 20, 2007 Share Posted August 20, 2007 Hi.. May I know What r u getting in $players var..? check in that.. Regards, Vijay Quote Link to comment https://forums.phpfreaks.com/topic/65669-including-array-in-sql-in/#findComment-328632 Share on other sites More sharing options...
padams Posted August 20, 2007 Author Share Posted August 20, 2007 $players comes from a list where users can select multiple values. The list is created dynamically and is made up of the first and last names of players belonging to our club. You can see the page at http://www.otterstouch.com/ottersdb/select3.php. It's ugly I know! Quote Link to comment https://forums.phpfreaks.com/topic/65669-including-array-in-sql-in/#findComment-328637 Share on other sites More sharing options...
padams Posted August 20, 2007 Author Share Posted August 20, 2007 Forgot to mention: the $players variable contains an array of integers. These are from the playerID column in the players table, and are the primary key for that table. Quote Link to comment https://forums.phpfreaks.com/topic/65669-including-array-in-sql-in/#findComment-329192 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.