$ POST和$ GET从下拉列表中获取价值

时间:2016-04-11 08:18:55

标签: php html get

a.html

function load(str)
{   
    xhttp.open("GET","a.php?q="+str,true);
    xhttp.send();
    }           
}        
<select name = "select"  onchange ="load(this.value)">                   
  <option selected = "selected">Select a movie</option>                   
  <option value= "asc">Name in ascending order</option>
  <option value = "genre">Genre</option>                           
</select>

a.php只会

$asc = $_POST['asc'];
$genre = $_POST['genre'];
if (!empty($_GET[$asc])) {
    $sql = "SELECT * FROM movies order by Name ASC";
} else if (!empty($_GET[$genre])) {
    $sql = "SELECT * FROM movies order by Genre ASC";
}
$db = mysql_connect("localhost","root","123"); 
$db_select = mysql_select_db('m',$db);
if ( ( $result = mysql_query( $sql, $db ) ) ) {
     echo $result;  
}

我想从下拉按钮中选择值。例如asc,并将值传递给a.php ($asc = $_POST['asc'])。我怎么能这样做?

0 个答案:

没有答案