2015-10-02 95 views
0

我有這樣打開新的頁面,然後點擊按鈕

<form action="plot.php" method="POST"> 
    <select name="variabel"> 
     <option value="no2">NO2</option> 
     <option value="so2">SO2</option> 
     <option value="ozone">ozone</option> 
     <option value="aerosol">aerosol</option> 
    </select> 
    <input type="submit" value="plot" style="width:500px;height:48px"> 

,並在文件組合框代碼名爲「plot.php」像這樣

<?php 
    $variabel = $_POST['variabel']; 

    if ($variabel = "no2") { 
    header("location:maps_no2.php"); 
    } else if ($variabel = "so2") { 
    header("location:maps_so2.php"); 
    } else if ($variabel = "ozone") { 
    header("location:maps_ozone.php"); 
    } else { 
    header("location:maps_aerosol.php"); 
    } 
?> 

是我想要的,當我選擇我的組合框中的一個項目,它將成爲另一個頁面打開後,我點擊「繪圖」按鈕的參數。 爲例,當我選擇NO2時,maps_no2.php將顯示。當我嘗試上面的代碼時,它只是在第一個條件下工作,儘管我選擇了so2。我該如何解決這個問題?任何人??請。

+0

你正在做的任務,而不是比較。 –

回答

1

這裏是你的問題:

<?php 
if $variabel = $_POST['variabel']; 

應該

<?php 
    if $variabel == $_POST['variabel']; 

如果你只需要使用單一=,它設置變量爲該值。那麼它永遠是真的。

+0

感謝您的回答,但它仍然是一樣的。它只是想去第一個條件:( – kenry

+0

我修復了我的答案,因爲我忘記了中頻部分。這就是我指的。 – durbnpoisn

+0

好吧謝謝:) – kenry

0

您應該使用==的比較

<?php 
    $variabel = $_POST['variabel']; 

    if ($variabel == "no2") { 
    header("location:maps_no2.php"); 
    } else if ($variabel == "so2") { 
    header("location:maps_so2.php"); 
    } else if ($variabel == "ozone") { 
    header("location:maps_ozone.php"); 
    } else { 
    header("location:maps_aerosol.php"); 
    } 
?> 
+0

哦,是的!謝謝它的作品:) – kenry

1

你要比較,在你的語句要分配改爲:

<?php 
    $variabel = $_POST['variabel']; 

    if ($variabel == "no2") { 
    header("location:maps_no2.php"); 
    } 
    else if ($variabel == "so2") 
    { 
    header("location:maps_so2.php"); 
    } 
    else if ($variabel == "ozone") 
    { 
    header("location:maps_ozone.php"); 
    } 
    else 
    { 
    header("location:maps_aerosol.php"); 
    } 
?> 
+0

最好還添加'退出;'每個標題後;-)我認爲OP是不知道這一點。 –

+0

哦,是的!謝謝它的作品:) – kenry

+0

好吧弗雷德謝謝你告訴我:) – kenry