2013-03-07 31 views
0

我怎样可以得到$ _GET获取与方法不同的值,从下拉菜单

问题不同的值是,我想有不同的选择不同的脚本得到

代码:

<Select NAME="offer"> 
<Option VALUE="status">Status</option> 
<Option VALUE="company">Advertisers</option> 
<Option VALUE="category">Categories</option> 
<Option VALUE="country">Countries</option> 
<Option VALUE="default_payout">Payouts</option> 
</Select> 

<?php if(isset($_GET['offer'])== status){ 
       include_once 'include/offer.php'; 
       include_once 'include/offer_tabel.php'; 
     } 

     if(isset($_GET['offer']) == 'company'){ 
       include_once 'include/advertiser.php'; 
       include_once 'include/advertiser_tabel.php'; 

} 
?> 

我在这里做错了吗?

回答

3

改变这个if(isset($_GET['offer'])== status

if(isset($_GET['offer']) && $_GET['offer'] == 'status') 
1

您正在使用错的,如果条件。使用:

if(isset($_GET['offer']) && $_GET['offer'] == 'status') 

同为公司

0

的问题是,你不能使用isset()与其他字符串比较。因为此函数将仅返回布尔值的值。此项更改,

<?php if(isset($_GET['offer']) && ($_GET['offer'] == 'status')){ 
       include_once 'include/offer.php'; 
       include_once 'include/offer_tabel.php'; 
     } 

     if(isset($_GET['offer']) && ($_GET['offer'] == 'company')){ 
       include_once 'include/advertiser.php'; 
       include_once 'include/advertiser_tabel.php'; 

     } 
?> 
1

您在脚麻:

if(isset($_GET['offer'])== status){ 

isset()函数返回一个bool值:http://php.net/manual/en/function.isset.php

好方法就写你的脚本:

<?php 
    if(isset($_GET['offer'])){ 
     switch(strtolower(trim($_GET['offer']))){ 
      case 'status': 
       // include your files for status offer 
      break; 

      case 'company': 
       // include your files for company offer 
      break; 

      default: 
       //Some default action 
      break; 
     } 
    } 
    else { 
     //No offer selected 
    } 
?> 
0

除了其他答案,请确保您的表单的方法是get而不是post;否则,您需要测试$_POST['offer']的值。

相关问题