I'm sorry but your code doesn't make sense at all. I'm surprised that you're getting that result at all. Let's walk through it.
Where are the quotes?
$array2[] = $itemz[place][id];
$array3[] = $itemz[place][location][city];
You're missing quotes here, please add them
$array2[] = $itemz['place']['id'];
$array3[] = $itemz['place']['location']['city'];
Array to String conversion
$sql = "select * from places where id=".$array2." and location=".$array3."";
This statement shouldn't work for 2 reasons.
Assuming that id
is a single field of INT and you have a bunch of INTs in $array2
you still can't compare them without a MySQL IN
.
You're converting from a PHP array to a string. That won't work.
Since you're running this in a loop $array2[]
and $array3[]
will continue to change and will grow.
So what you're actually trying to do is come up with a query like
$sql = "SELECT *
FROM places
WHERE
id IN (" . implode(',', $array2) . ") AND
location IN (" . implode(',', $array3) . ")";
But this makes no sense at all because as the loop continues you're retrieving the same data incrementally.
So I think what you actually want to do is
$sql = "SELECT *
FROM places
WHERE
id = {$itemz['place']['id']} AND
location = {$itemz['place']['location']['city']}";
This is most probably what you need. This retrieves the rows for each row as you iterate through you array.
A couple of improvements I would do is.
Run your query once after the looping is done so you only have to run the query one time and not n
times.
Also, consider retrieving only the columns you need instead of doing SELECT *