RCB
RCB

Reputation: 99

Drop Down List - Choice written in URL

I have created a drop down list calling values from a database. I have an issue that when the choice from the drop down is chosen the URL stays the same.

This is the code:

<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>";
}}

I want to write the choice in the url for example: www.mydomain.com/?country=unitedkingdom

Upvotes: 0

Views: 56

Answers (2)

Sherin Jose
Sherin Jose

Reputation: 2526

An extra " is in your action attribute of <form>. Remove that. And also change the method to get

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

And you need to change the dropdown name to country . ie.,

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

Upvotes: 1

Tommy
Tommy

Reputation: 391

You have to use GET method in form to be able to do that

Upvotes: 0

Related Questions