woolyg Posted February 2, 2009 Share Posted February 2, 2009 Hi all, Please check this out: <?php $get_subscribed_players1 = "SELECT game_subscriptions.user_id FROM game_subscriptions WHERE game_subscriptions.game_id='".$game_id."' AND game_subscriptions.active='1'"; $run_subscribed_players1 = mysql_query($get_subscribed_players1); //Get the array of currently active players in this game for($k=1; $k<=$num_subscribed_players1;){ // FOR 107 while($array_subscribed_players = mysql_fetch_assoc($run_subscribed_players1)){ // While 107 $array_user_id = $array_subscribed_players['user_id']; if($k!=$num_subscribed_players){ $array_comma = ",";} else {$array_comma = "";} $array_of_subscribers.="'".$array_user_id."'".$array_comma; $k++; }// While 107 }// FOR 107 $needle = '10'; $test_array = array($array_of_subscribers); if(in_array($needle, $test_array)){ // IF 138 echo "Signed in - In Array"; } else if(!in_array($needle, $test_array)){ // IF 138 echo "Signed in - NOT In Array"; } // IF 138 ?> The code should be seeing that 10 is part of the array, and saying "Signed in - NOT In Array", but it's not seeing the number in the array. Can anyone see what I might be doing wrong here? Thanks, Woolyg Link to comment https://forums.phpfreaks.com/topic/143425-in_array-weirdness/ Share on other sites More sharing options...
sasa Posted February 2, 2009 Share Posted February 2, 2009 change line $array_of_subscribers.="'".$array_user_id."'".$array_comma; to $array_of_subscribers[]=$array_user_id; and if(in_array($needle, $test_array)){ to if(in_array($needle, $array_of_subscribers)){ Link to comment https://forums.phpfreaks.com/topic/143425-in_array-weirdness/#findComment-752338 Share on other sites More sharing options...
killah Posted February 2, 2009 Share Posted February 2, 2009 Shouldn't your for function look like this: for($k = 1; $k <= mysql_num_rows($num_subscribed_players1)) Link to comment https://forums.phpfreaks.com/topic/143425-in_array-weirdness/#findComment-752342 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.