loshyt Posted October 28, 2010 Share Posted October 28, 2010 i have a problem i cant solved for cople of hours! this is the function: function show_posts($user_id,$limit=0){ $posts = array(); $user_string = implode(',', $user_id); $extra = " and id in ($user_string) "; if ($limit > 0){ $extra = "limit $limit"; }else{ $extra = ''; } $sql = "SELECT userid, caption, stamp, filename FROM photographs WHERE userid in ($user_string) order by stamp desc $extra"; //echo $sql; $result = mysql_query($sql) or die(mysql_error()) ; while($data = mysql_fetch_object($result)){ $posts[] = array( 'stamp' => $data->stamp, 'userid' => $data->userid, 'caption' => $data->caption, 'filename' => $data->filename, ); } return $posts; } and thats the full error: Warning: implode() [function.implode]: Invalid arguments passed in C:\wamp\www\includes\functions.php on line 12 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 ') order by stamp desc' at line 2 and the intresting thing that if i echo the sql i get a working one i checked it in phpmyadmin + it shows what it need to show in the index.php if i comment the "or die(mysql_error()) " here the sql when its do echo SELECT userid, caption, stamp, filename FROM photographs WHERE userid in (4,7,2) order by stamp desc limit 5 so y the hell this problem is keep coming? i really cant understand what wrong! :-\ tnx for the help! Quote Link to comment https://forums.phpfreaks.com/topic/217085-warning-implode-functionimplode-invalid-arguments-passed-in/ Share on other sites More sharing options...
joel24 Posted October 28, 2010 Share Posted October 28, 2010 the mysql IN conditions need to be enclosed in brackets, surrounded by ' if they are strings (no need for integers) and then separated by , i.e. SELECT FROM tables WHERE field IN ('first', 'second', 32, 58) as for the error with the implode function, is $user_id an array? Quote Link to comment https://forums.phpfreaks.com/topic/217085-warning-implode-functionimplode-invalid-arguments-passed-in/#findComment-1127447 Share on other sites More sharing options...
loshyt Posted October 28, 2010 Author Share Posted October 28, 2010 the mysql IN conditions need to be enclosed in brackets, surrounded by ' if they are strings (no need for integers) and then separated by , i.e. SELECT FROM tables WHERE field IN ('first', 'second', 32, 58) as for the error with the implode function, is $user_id an array? i didnt get what you saying should i do: WHERE userid 'in ($user_string)' order by stamp desc $extra"; if u can show me exactly on my code it will be clearer. and ofcurse $user_id is an array. tnx waiting 4 response Quote Link to comment https://forums.phpfreaks.com/topic/217085-warning-implode-functionimplode-invalid-arguments-passed-in/#findComment-1127449 Share on other sites More sharing options...
trq Posted October 28, 2010 Share Posted October 28, 2010 i didnt get what you saying should i do: $user_string = "'". implode("','", $user_id) . "'"; and ofcurse $user_id is an array The error is quite clear, $user_id is not an array. Quote Link to comment https://forums.phpfreaks.com/topic/217085-warning-implode-functionimplode-invalid-arguments-passed-in/#findComment-1127462 Share on other sites More sharing options...
loshyt Posted October 28, 2010 Author Share Posted October 28, 2010 i didnt get what you saying should i do: $user_string = "'". implode("','", $user_id) . "'"; and ofcurse $user_id is an array The error is quite clear, $user_id is not an array. i dont get it i check everything and its set like an array ... but i tried to do is_array func to check and its working! U r the man !! Quote Link to comment https://forums.phpfreaks.com/topic/217085-warning-implode-functionimplode-invalid-arguments-passed-in/#findComment-1127478 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.