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); 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). ")"; 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? 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 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! 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. 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
Archived
This topic is now archived and is closed to further replies.