根据页面加载的位置提交表单

时间:2017-02-24 04:09:48

标签: php html mysql

我有一个下拉菜单,我用作该国家的选择器来查看我们的位置。

下拉列表目前正在运行,但我希望它能够加载用户当前的国家/地区,然后才能从下拉列表中选择它,以便自动向其显示其所在国家/地区的地理位置列表。

目前我有下拉列表检索用户国家/地区但是它没有提交表单,它只显示"选择"值。

这是我的代码,包括sql:

<?php

require_once( DIR_WS_CLASSES . 'geoplugin.class.php');
$geoplugin = new geoPlugin();
$geoplugin->locate();

echo $geoplugin->countryCode;

echo $geoplugin->countryName;

?>
<div style="padding:80px 0 20px 20px;border-bottom:1px solid #a6a6a6; ">
<h1 style="color:#000"><?php echo LOCATION_TITLE ;?></h1>
</div>

<div style="padding:20px 0px 0px 1%;">
<form action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>" method="post"  >

    <select name="selectboxvalue" onchange="this.form.submit();" id="selectboxvalue"   >

        <option>SELECT A COUNTRY</option>
        <option value="<?php $geoplugin->countryCode; ?>" <?php if ($geoplugin->countryCode == 'US' || $_POST["selectboxvalue"]=="US" ) echo "selected=\"selected\""; ?>>USA</option>
        <option value="canada" <?php if ( $geoplugin->countryCode == 'CA'|| $_POST["selectboxvalue"]=="canada" ) echo "selected=\"selected\""; ?>>Canada</option>
        <option value="international" <?php if ( $_POST["selectboxvalue"]=="international" ) echo "selected"; ?>> International</option>
    </select>

</form>
</div>
<?php




$location_query_raw =  "select l.storetitle,l.storeimage, l.country, l.state, l.city, l.postal, l.address, l.phone, l.storelink, l.latitude,l.longitude, l.sortorder, l.status from locations l";


switch ($_POST['selectboxvalue']) {
    case "US":
        $location_query_raw .= "  where l.country like \"%USA%\" ORDER BY l.state ";
        break;
    case "canada":
        $location_query_raw .= " where l.country like \"%CA%\" ORDER BY l.state";
        break;
    case "international":
        $location_query_raw .= " where l.country not like \"%USA%\" and l.country not like \"%CA%\" ORDER BY l.state";
        break;
    default:
        $location_query_raw .= " order by l.state";
        break;
}

$location_query= tep_db_query( $location_query_raw);

1 个答案:

答案 0 :(得分:1)

我发现了问题......你没有回应价值..: - )

<option value="<?php $geoplugin->countryCode; ?>"

只需添加回声即可发布值! :

<option value="<?php echo $geoplugin->countryCode; ?>"