ohdang888 Posted August 6, 2008 Share Posted August 6, 2008 $result = mysql_query("SELECT COUNT(id) FROM `friends` WHERE (`1`='$id2' AND `2` IN ($friends_of_1)) OR (`2`='$id2' AND `1` IN ($friends_of_1))")or die(mysql_error()); $friends_of_1 is an array with mulitple values... basically what this is doing is counting the mutual friends. i'm getting this error: Unknown column 'Array' in 'where clause' Link to comment https://forums.phpfreaks.com/topic/118391-solved-in-statement-with-array/ Share on other sites More sharing options...
PFMaBiSmAd Posted August 6, 2008 Share Posted August 6, 2008 The mysql IN() function expects a coma-separated list of numbers or strings. A php array is neither of those. Link to comment https://forums.phpfreaks.com/topic/118391-solved-in-statement-with-array/#findComment-609292 Share on other sites More sharing options...
ohdang888 Posted August 6, 2008 Author Share Posted August 6, 2008 ohhh ok thanks. So how would i turn that array into a set of comma's??? Link to comment https://forums.phpfreaks.com/topic/118391-solved-in-statement-with-array/#findComment-609293 Share on other sites More sharing options...
ohdang888 Posted August 6, 2008 Author Share Posted August 6, 2008 UPDATE: GOT IT WORKING. THANKS ok i;'ve got this: and this not the error from using $in You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') OR (`2`='4' AND `1` IN (7, 2, 8, 3, ))' at line 1 <?php $in = " IN ("; foreach($friends_of_1 as $value){ $value = $sec->clean($value); $in = $in.$value.', '; } $in = $in.' )'; echo $in; ?> Link to comment https://forums.phpfreaks.com/topic/118391-solved-in-statement-with-array/#findComment-609294 Share on other sites More sharing options...
trq Posted August 6, 2008 Share Posted August 6, 2008 $result = mysql_query("SELECT COUNT(id) FROM `friends` WHERE (`1`='$id2' AND `2` IN ('" . explode("','", $friends_of_1) ."')) OR (`2`='$id2' AND `1` IN ('" . explode("','", $friends_of_1) ."'))")or die(mysql_error()); Link to comment https://forums.phpfreaks.com/topic/118391-solved-in-statement-with-array/#findComment-609316 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.