2012-07-11 105 views
0

这是我的代码为我的下拉菜单。在一台服务器上显示适当的数字。但另一方面,我在下拉菜单中看到了“>”的每个选项。我猜这与php.ini文件有关,但我不确定...如何解决下拉菜单?所有的选择显示“>”

<?php 
// connect to the database 
require 'connect.php'; 

// ------------------------------------------------------------------------------------------------------- 
// Drop Down Menu to choose Start and End dates 
$startyear = ""; 
$startmonth = ""; 
$startday = ""; 
$endyear = ""; 
$endmonth = ""; 
$endday = ""; 

// Array of values for form 
$year = range(1998,2012); 
$month = range(01,12); 
$day = range(01,31); 

if($_SERVER['REQUEST_METHOD']=='POST') 
{ 
    foreach($_POST as $key=>$value) 
    { 
     if(is_numeric($value)) 
     { 
      $$key = $value; 
     } 
    } 
} 

?> 

<form name='update' action='' method='POST'> 
Start: <select name='startyear'> 
    <?php foreach(array_reverse($year) as $y):?> 
    <option value="<?=$y?>"<?=((isset($startyear) && $startyear == $y)?' selected':null)?>><?=$y?></option> 
    <?php endforeach;?> 
</select> 
<select name='startmonth'> 
    <?php foreach($month as $m): $m = str_pad($m, 2, "0", STR_PAD_LEFT);?> 
    <option value="<?=$m;?>"<?=((isset($startmonth) && $startmonth == $m)?' selected':null)?>><?=$m;?></option> 
    <?php endforeach;?> 
</select> 
    <select name='startday'> 
    <?php foreach($day as $d): $d = str_pad($d, 2, "0", STR_PAD_LEFT);?> 
    <option value="<?=$d;?>"<?=((isset($startday) && $startday == $d)?' selected':null)?>><?=$d;?></option> 
    <?php endforeach;?> 
</select> 
<br> 
End: <select name='endyear'> 
    <?php foreach(array_reverse($year) as $y):?> 
    <option value="<?=$y?>"<?=((isset($endyear) && $endyear == $y)?' selected':null)?>><?=$y?></option> 
    <?php endforeach;?> 
</select> 
<select name='endmonth'> 
    <?php foreach($month as $m): $m = str_pad($m, 2, "0", STR_PAD_LEFT);?> 
    <option value="<?=$m;?>"<?=((isset($endmonth) && $endmonth == $m)?' selected':null)?>><?=$m;?></option> 
    <?php endforeach;?> 
</select> 
    <select name='endday'> 
    <?php foreach($day as $d): $d = str_pad($d, 2, "0", STR_PAD_LEFT);?> 
    <option value="<?=$d;?>"<?=((isset($endday) && $endday == $d)?' selected':null)?>><?=$d;?></option> 
    <?php endforeach;?> 
</select> 
<input type='submit' value='View'/> 
</form> 
+0

那里的反对票的理由? – myom 2012-07-11 20:21:09

回答

2

尝试交换较长的PHP标签。

<?=成为<?php echo<?成为<?php

一些配置让您用简短的形式;所有的PHP配置都可以让你使用更长的配置。

+0

这工作。谢谢! – myom 2012-07-11 18:37:15

+0

不客气。通常总是值得使用更长的PHP标签,因为它使您的代码更加便携。 – andrewsi 2012-07-11 18:39:08

1

变化:

selected':null)?>><?=$y?></option> 

selected':null)?><?=$y?></option> 

有太多的>