I have an array $ziparray that I am trying to use in a MySQL query to check against a database column named 'zip'. The following code seems logical to me, but I am getting an error:
Catchable fatal error: Object of class stdClass could not be converted to string in...
$ziparrayimplode = implode(",", $ziparray);
$listinghistoryquery = "SELECT * FROM listings WHERE zip IN ($ziparrayimplode) ORDER BY list_ts DESC";
$listinghistory = mysql_query($listinghistoryquery) or die('SQL Error :: '.mysql_error());
I am absolutely certain the $ziparray is an array. Can anyone tell me how to make this query work? Here is the code used to create the array..
$countyzipquery = mysql_query("SELECT city_zip FROM dev_cities WHERE city_state='$state' AND city_county='$county' AND city_name='$city'");
$ziparray = array();
while (($ziparrayrow = mysql_fetch_object($countyzipquery)) !== FALSE) {
$ziparray[] = $ziparrayrow;
Here is the output of var_dump($ziparray)
array(1) { [0]=> object(stdClass)#3 (1) { ["city_zip"]=> string(5) "63028" } }
$ziparraymight be an array, but it seems to contain at least onestdClassobject, which fails to convert to a string for theimplodeoperation itself. Please include the output ofvar_dump($ziparray)in your question.mysql_fetch_object) into$ziparrayand then you're trying to concatenate those objects.