靠近特定邮政编码的用户:PHP mysql

靠近特定邮政编码的用户:PHP mysql,php,mysql,arrays,search,zip,Php,Mysql,Arrays,Search,Zip,新年快乐!假设user1位于邮政编码12345处。我想在该邮政编码X英里内找到其他用户 首先,我创建了表单: <div id="wrapper"> <form action="L1.php" method="post"> <select name="radius"> <option value="5">5</option> <option value="10

新年快乐!假设user1位于邮政编码12345处。我想在该邮政编码X英里内找到其他用户

首先,我创建了表单:

<div id="wrapper">
    <form action="L1.php" method="post">

        <select name="radius">
            <option value="5">5</option>
            <option value="10">10</option>
            <option value="20">20</option>
            <option value="30">30</option>
            <option value="40">40</option>
            <option value="50">50</option>
        </select>
        Miles within Zip Code:


        <input name="zip"  type="text" value="13126" />
        <input type="submit" value="refine" />
    </form>
</div>

5.
10
20
30
40
50
邮政编码内的英里数:
现在我列出了12345(L1.php)X英里范围内的所有邮政编码:


如果您在
$items
中有邮政编码,那么我认为您不需要对所有客户Zipcode使用
$itemsz

首先,您需要格式化$items数组,如下所示:

$zips=(12345123461234712348)

然后在customer中运行如下查询:

Select * from customer where customer.zipcode IN $zips
演示:
示例代码:

$items =array( '0' => array( 'zip_code' => 13121, 'latitude' => 43.483379, 'longitude' => -76.315044, 'city' => 'New Haven', 'state' => 'NY', 'county' => 'Oswego' ), '1' => array( 'zip_code' => 13126, 'latitude' => 43.465388 ,'longitude' => -76.342172 ,'city' => 'Oswego' ,'state' => 'NY', 'county' => 'Oswego' ) );

$strzipCodes="";
foreach($items as $item){

    $strzipCodes .= $item['zip_code']." ,";

}
$strzipCodes = rtrim($strzipCodes,',');

$sql ="SELECT * FROM customer where zip IN(".$strzipCodes.")";
echo $sql;
// then execute query we will get all users inside those zipcodes

我想你明白了。

我有点困惑。你在数组中有zipcodes,你想从zipcodes中获取所有用户。对吗?可能尝试将邮政编码数组转换为逗号分隔的字符串,然后执行
SELECT*FROM customer WHERE zip IN($comma\u separated\u zip\u code)
Yes,$items是距离12345 5英里内的邮政编码数组$itemsz是所有客户的邮政编码数组。@Aaron F:您想要完整的邮政编码,然后给我打印输出($items);这是有道理的。我写了以下内容:$query2=“Select*FROM customer WHERE customer.zip IN$items”;但仍然得到转换错误。你认为我的$items不是数组吗?这是我的print\r($items);输出:数组([0]=>Array([zip_code]=>13121[纬度]=>43.483379[经度]=>76.315044[城市]=>NewHaven[州]=>NY[县]=>Oswego)[1]=>Array([zip_code]=>13126[纬度]=>43.465388[经度]=>76.342172[城市]=>Oswego[州]=>NY[县]=>Oswego])@Aaron F:我已经更新了答案。现在应该可以了。
$items =array( '0' => array( 'zip_code' => 13121, 'latitude' => 43.483379, 'longitude' => -76.315044, 'city' => 'New Haven', 'state' => 'NY', 'county' => 'Oswego' ), '1' => array( 'zip_code' => 13126, 'latitude' => 43.465388 ,'longitude' => -76.342172 ,'city' => 'Oswego' ,'state' => 'NY', 'county' => 'Oswego' ) );

$strzipCodes="";
foreach($items as $item){

    $strzipCodes .= $item['zip_code']." ,";

}
$strzipCodes = rtrim($strzipCodes,',');

$sql ="SELECT * FROM customer where zip IN(".$strzipCodes.")";
echo $sql;
// then execute query we will get all users inside those zipcodes