Jump to content

Warning: implode() [function.implode]: Invalid arguments passed in


loshyt

Recommended Posts

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!

 

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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 !! 8)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.