php级联菜单的实现

 

<?php session_start();
      if($_GET[year]!="" ){ $_SESSION["year"]=$_GET[year]; }
      if($_GET[month]!=""){ $_SESSION["month"]=$_GET[month]; }
?>


<script language="javascript">
  function selectyear(x){    
      window.location.href='noname1.php?year='+x;
  }
  function selectmonth(x){
      window.location.href='noname1.php?month='+x+"&year="+form1.selectyear1.value;
  }
</script>

<form  name="form1">   
<select name="selectyear1" size="1" onChange="selectyear(this.value);"> 
<?php
    $year="2008,2009,2010,2011,2012,2013,2014,2015";
    $years=split(",",$year);
    $count=count($years);
    for($i=0;$i<$count;$i++){
    $result=$years[$i];     
?> 
    <option value="<?php echo $result;?>"
   
<?php
      if($_SESSION[year]==$result)
{
     echo "selected=\"selected\"";
}?>           
       ><?php echo $result;}?></option>         
      
</select>

<select name="selectmonth1" size="1" onChange="selectmonth(this.value);">
<?php
    $Month="1,2,3,4,5,6,7,8,9,10,11,12";
    $Months=split(",",$Month);
    $count=count($Months);
    for($i=0;$i<$count;$i++){
    $result=$Months[$i];
?> 
    <option value="<?php echo $result;?>"
   
<?php
      if($_SESSION[month]==$result)
{
     echo "selected=\"selected\"";
}?>           
       ><?php echo $result;}?></option>         
</select>

<select name="selectdate1" size="1">
<?php
    $date="1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31";
    $date1="1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30";
    $date2="1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29";
    $date3="1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28";

    if($_GET[month]=="")
    {
    $dates=split(",",$date);   
    }

    if ($_SESSION[month]=="1" or $_SESSION[month]=="3" or $_SESSION[month]=="5" or $_SESSION[month]=="7" or $_SESSION[month]=="8" or $_SESSION[month]=="10" or $_SESSION[month]=="12")
    {
    $dates=split(",",$date);
    }
    if ($_SESSION[month]=="4" or $_SESSION[month]=="6" or $_SESSION[month]=="11")
    {
    $dates=split(",",$date1);
    }
    if ((integer)$_SESSION[year]%4==0 and $_SESSION[month]=="2")
    {
    $dates=split(",",$date3);
    }   
    if ((integer)$_SESSION[year]%4!=0 and $_SESSION[month]=="2")
    {
    $dates=split(",",$date2);
    }       
    {
    $count=count($dates);
    for($i=0;$i<$count;$i++){
    $result=$dates[$i];
    echo "<option>$result</option>";}
    }  
?>
</select>
 
</form>

posted on 2009-01-11 21:48  费戈  阅读(839)  评论(0编辑  收藏  举报

导航