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!

 

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?

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

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)

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.