下拉列表 - 用URL写的选择

时间:2014-02-13 09:30:58

标签: php html

我创建了一个从数据库调用值的下拉列表。我有一个问题,当选择下拉选项时,URL保持不变。

这是代码:

<form method="get" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<select name="country" onchange='this.form.submit()'> 
    <?php $result= mysql_query('SELECT DISTINCT country FROM roaming_testing ORDER BY country ASC'); ?> 
<option value="x" selected>Select your destination</option>
    <?php while($row= mysql_fetch_assoc($result)) { ?> 
        <option value="<?php echo htmlspecialchars($row['country']);?>" > 
            <?php echo htmlspecialchars($row['country']); ?> 
        </option> 
    <?php } ?> 
<input type="hidden" name="action" value="submit" /><br>
</select>
</form>

<?php
if(isset($_GET["action"]) && $_GET["action"] == "submit") { 


    $results= $wpdb->get_results("SELECT * FROM roaming_testing WHERE country='$_GET[country]'");
    $zones= $wpdb->get_results("SELECT * FROM roaming_rates WHERE zone IN (SELECT zone FROM roaming_testing WHERE country='$_GET[country]')");
    $operators_postpaid= $wpdb->get_results("SELECT * FROM roaming_testing WHERE country='$_GET[country]' AND postpaid_roaming=1");
    $operators_prepaid= $wpdb->get_results("SELECT * FROM roaming_testing WHERE country='$_GET[country]' AND prepaid_roaming=1");


if (empty($results))
    { echo '<h3 style="color:red;">No Results</h3>';} 
else 
    {foreach ( $results as $result ) {
        foreach ( $zones as $zone ){
}}}

?>

<?php


echo '<div class="roaming-header">'.htmlspecialchars($_GET["country"]).'</div>'.'<br>';

if (empty($operators_postpaid)){
echo "
<span style='font-size:21px; font-family:Arial, Helvetica, sans-serif; color:#00abbd; font-weight:bold'>Pay Monthly</span>
<table cellpadding='6' cellspacing='0' border='0' width='100%'>
    <tr>
        <td>
            <p class='rates'>Available soon</p>
        </td>
    </tr>
<tr><td></td></tr>
<tr><td></td></tr>
<tr><td></td></tr>
<tr><td></td></tr>
<tr><td></td></tr>
<tr><td></td></tr>
<tr><td></td></tr>
</table>

";
}else{

echo "

<table width='620'>
<tr>

<td width='50%'>

<span style='font-size:21px; font-family:Arial, Helvetica, sans-serif; color:#00abbd; font-weight:bold'>Pay Monthly</span>
    <table width='310' cellpadding='6' cellspacing='0' border='0' style='border-color:#00abbd; border-width:0px; border-style:solid; padding:3px'>

    <tr bgcolor='#eeeeee'>
        <td width='160'>
            <p class='rates' style='color:#00abbd;'><strong>Call to $result->country</strong></p>
        </td>

        <td>
            <p class='rates'>&euro; $zone->calling_visiting_country /min</p>
        </td>
    </tr>

    <tr>
        <td>
            <p class='rates' style='color:#00abbd;'><strong>Call to Malta</strong></p>
        </td>

        <td>
            <p class='rates'>&euro; $zone->calling_malta/min</p>
        </td>
    </tr>

    <tr bgcolor='#eeeeee'>
        <td>
            <p class='rates' style='color:#00abbd;'><strong>Call to Zone $result->Zone </strong> </p>
        </td>

        <td>
            <p class='rates'>&euro; $zone->calling_visiting_country /min</p>
        </td>
    </tr>

    <tr>
        <td>
            <p class='rates' style='color:#00abbd;'><strong>Calling other Zones</strong></p>
        </td>

        <td>
            <p class='rates'>&euro; $zone->calling_other_countries /min</p>
        </td>
    </tr>

    <tr bgcolor='#eeeeee'>
        <td>
            <p class='rates' style='color:#00abbd;'><strong>Receiving Calls</strong></p>
        </td>

        <td>
            <p class='rates'>&euro; $zone->receiving_call /min</p>
        </td>
    </tr>

    <tr>
        <td>
            <p class='rates' style='color:#00abbd;'><strong>Data</strong></p>
        </td>

        <td>
            <p class='rates'> &euro; $zone->data</p>
        </td>
    </tr>

    <tr bgcolor='#eeeeee'>
        <td>
            <p class='rates' style='color:#00abbd;'><strong>SMS</strong></p>
        </td>

        <td>
            <p class='rates'>&euro; $zone->sms</p>
        </td>
    </tr>

    <tr>
        <td>
            <p class='rates' style='color:#00abbd;'><strong>MMS</strong></p>
        </td>
        ";

if ( $result->Zone == 1){
        echo "<td>
            <p class='rates'>&euro; $zone->data</p>             
        </td>
    </tr>
</table>
";} else{

echo "
        <td>
            <p class='rates'>&euro; $zone->mms + €$zone->data</p>               
        </td>
    </tr>
</table>
";}
}

if (empty($operators_prepaid)){
echo "
<td width='50%'>
<span rel='country2' style='font-size:21px; font-family:Arial, Helvetica, sans-serif; color:#a7cf3a; font-weight:bold'>Prepaid & Hybrid</span>
    <table width='310' cellpadding='6' cellspacing='0' border='0' style='border-color:#00abbd; border-width:0px; border-style:solid; padding:3px'>
</table>
";
}else{
echo "
<td width='50%'>
<span rel='country2' style='font-size:21px; font-family:Arial, Helvetica, sans-serif; color:#a7cf3a; font-weight:bold'>Prepaid & Hybrid</span>
    <table width='310' cellpadding='6' cellspacing='0' border='0' style='border-color:#00abbd; border-width:0px; border-style:solid; padding:3px'>

    <tr bgcolor='#eeeeee'>
        <td width='160'>
            <p class='rates' style='color:#a7cf3a;'><strong>Call to $result->country</strong></p>
        </td>

        <td>
            <p class='rates'>&euro; $zone->calling_visiting_country /min</p>
        </td>
    </tr>

    <tr>
        <td>
            <p class='rates' style='color:#a7cf3a;'><strong>Call to Malta</strong></p>
        </td>

        <td>
            <p class='rates'>&euro; $zone->calling_malta/min</p>
        </td>
    </tr>

    <tr bgcolor='#eeeeee'>
        <td>
            <p class='rates' style='color:#a7cf3a;'><strong>Call to Zone $result->Zone </strong> </p>
        </td>

        <td>
            <p class='rates'>&euro; $zone->calling_visiting_country /min</p>
        </td>
    </tr>

    <tr>
        <td>
            <p class='rates' style='color:#a7cf3a;'><strong>Calling other Zones</strong></p>
        </td>

        <td>
            <p class='rates'>&euro; $zone->calling_other_countries /min</p>
        </td>
    </tr>

    <tr bgcolor='#eeeeee'>
        <td>
            <p class='rates' style='color:#a7cf3a;'><strong>Receiving Calls</strong></p>
        </td>

        <td>
            <p class='rates'>&euro; $zone->receiving_call /min</p>
        </td>
    </tr>

    <tr>
        <td>
            <p class='rates' style='color:#a7cf3a;'><strong>Data</strong></p>
        </td>

        <td>
            <p class='rates'> &euro; $zone->data</p>
        </td>
    </tr>

    <tr bgcolor='#eeeeee'>
        <td>
            <p class='rates' style='color:#a7cf3a;'><strong>SMS</strong></p>
        </td>

        <td>
            <p class='rates'>&euro; $zone->sms</p>
        </td>
    </tr>

    <tr>
        <td>
            <p class='rates' style='color:#a7cf3a;'><strong>MMS</strong></p>
        </td>";

/*------------------------------------------------------------------------------------------------
        check for zone 1 for MMS rating
--------------------------------------------------------------------------------------------------*/

        if ( $result->Zone == 1){
echo "
        <td>
            <p class='rates'>&euro; $zone->data</p>             
        </td>
";}

else{

echo "  
        <td>
            <p class='rates'>&euro; $zone->mms + €$zone->data</p>               
        </td>

";
}

echo "
</tr>
</table>
</table>
";
}
/*------------------------------------------------------------------------------------------------
        Loops for Roaming Operators
--------------------------------------------------------------------------------------------------*/

echo "While in $result->country you can use the following networks: <br><br>";

if (empty($operators_postpaid)){
echo "Available networks for Pay Monthly customers<br>";
echo "Service will be available soon<br>";
}else{
echo "Available networks for Pay Monthly customers";
foreach ( $operators_postpaid as $operator_postpaid ){
    echo "<li>$operator_postpaid->operator</li>";
}}

echo "<br>";

if (empty($operators_prepaid)){
echo "Available networks for Prepaid customers<br>";
echo "Service will be available soon<br>";
}else{
echo "Available networks for Prepaid customers";
foreach ( $operators_prepaid as $operator_prepaid ){
    echo "<li>$operator_prepaid->operator</li>";
}}

我想在网址中写下选项,例如:www.mydomain.com/?country = unitedkingdom

2 个答案:

答案 0 :(得分:1)

额外的"位于<form>的操作属性中。删除它。并将方法更改为get

<form method="get" action="<?php echo $_SERVER['PHP_SELF']; ?>">
//elements
</form>

您需要将下拉名称更改为country。即,

<select name="country" onchange='this.form.submit()'>

答案 1 :(得分:0)

你必须在表单中使用GET方法才能做到这一点