我无法获得" $ optioncodesOut"变量以扩展在" $ showshop"选择语句。这只是在我的旧mysql_query()中工作,但我无法在这里工作。我已经确认这实际上是一个输出。
<?php
$servername = "localhost";
$username = "root";
$password = "password";
$dbname = "database";
$radius = "50"; //("'. $radius .'")
$lat = "33.776"; //("'. $lat .'")
$lon = "-95.7128"; //("'. $lon .'")
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// select statment
$optioncodes = 'SELECT zip_code, latitude, longitude, statename, city,
ROUND((ACOS((SIN(33.776/57.2958) * SIN(latitude/57.2958)) +
(COS(("'. $lat .'")/57.2958) * COS(latitude/57.2958) *
COS(longitude/57.2958 - ("'. $lon .'")/57.2958))))
* 3963) AS distance
from tblzipcode
WHERE (latitude >= ("'. $lat .'") - (("' . $radius . '")/111))
And (latitude <= ("'. $lat .'") + (("' . $radius . '")/111))
AND (longitude >= ("'. $lon .'") - (("' . $radius . '")/111))
AND (longitude <= ("'. $lon .'") + (("' . $radius . '")/111))
ORDER BY distance';
$result2 = $conn->query($optioncodes);
if ($result2->num_rows > 0) {
while($row2 = $result2->fetch_array()) {
$optioncodesOut = $row2['zip_code'] . ",";
echo $optioncodesOut;
}
$showshop = 'select id, attn, addr1, addr2, addr3, city, state, country, zip, phone_number, fax, web_site_url, delaerwebid, ARCUSTO_ID, CUSTNO as dealer from DEALERLOCATOR where zip in ("'.$optioncodesOut.'")';
$result = $conn->query($showshop);
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
echo '<br />' . $row['zip'] . ' ' . $row['attn'] . $row['ARCUSTO_ID'] . '<br />';
}
}
}
echo '<br />'.$showshop;
?>
&#34; $ optioncodesOut&#34;
的当前输出75425,75486,75421,75473,75460,75461,75470,75462,75462,75411,75477,74738,74759,75488,75446,74727,75416,74743,75450,75492,74723,74723,75443,75468,75438,75469,75441,74756,75434,75435,75432,75415,75449,74726,74760,75496,75481,
正如您所看到的那样,唯一的邮政编码显示在&#34; $ optioncodesOut&#34;是&#34; 75481&#34;。
select id, attn, addr1, addr2, addr3, city, state, country, zip, phone_number, fax, web_site_url, delaerwebid, ARCUSTO_ID, CUSTNO as dealer from DEALERLOCATOR where zip in ("75481,")
答案 0 :(得分:1)
也许这是一个连接问题。 尝试更改此行:
$optioncodesOut = $row2['zip_code'] . ",";
如下:
$optioncodesOut = $optioncodesOut . $row2['zip_code'] . ",";