我正在编码组的位置,用户可以根据位置进行搜索以找到离他们最近的组。字段是:国家、州、城市、社区。假设美国有十个组——我不希望它列出选项 USA 十次。我添加了一个 strpos 以便它只会列出一次,但我得到了一个错误。
这是php代码:
<?php
$myQuery = "select country, state, city, neighborhood from groups WHERE group_status = 'open to new members'";
$rs = mysql_query($myQuery);
$country_options = $state_options = $city_options = $neighborhood_options = '';
while($get_row = mysql_fetch_assoc($rs)){
$pos_country = strpos($get_row['country'], $country_options);
if($pos_country === false) {
echo $country_options .= "<option value='" . $get_row['country'] . "'>" . $get_row['country'] . "</option>";}
$pos_state = strpos($get_row['state'], $state_options);
if($pos_state === false) {
echo $state_options .= "<option value='" . $get_row['state'] . "'>" . $get_row['state'] . "</option>";}
$pos_city = strpos($get_row['city'], $city_options);
if($pos_city === false) {
echo $city_options .= "<option value='" . $get_row['city'] . "'>" . $get_row['city'] . "</option>";}
$pos_neighborhood = strpos($get_row['neighborhood'], $neighborhood_options);
if($pos_neighborhood === false) {
echo $neighborhood_options .= "<option value='" . $get_row['neighborhood'] . "'>" . $get_row['neighborhood'] . "</option>";}
}
?>
它输出以下错误:
警告:strpos():第 66 行的 sidebar.php 中的空分隔符
警告:strpos():第 70 行的 sidebar.php 中的空分隔符
警告:strpos():第 73 行的 sidebar.php 中的空分隔符
警告:strpos():第 76 行的 sidebar.php 中的空分隔符
在错误下方,它有一个带有正确字段的漂亮表单:国家、州、城市、社区。它只是多次列出相同的国家。