$getyear = strftime("%Y", strtotime($row['rpt_date']));
$getmonth = strftime("%b", strtotime($row['rpt_date']));
$getday = strftime("%a", strtotime($row['rpt_date']));Year :  <select>
           //年份
        </select> 
        <select>
            //月份
        </select> 
        <input type="submit" name="submit" value="Go">
        <br><br>
        <a href="InsertReport.php">[Update Report]</a>
        <table border='1'>
            <tr bgcolor=gray>
                <th >Date</th>
                <th>No.of Post</th>
                <th>No.of View</th>
            </tr>
            <?php
            do {
                $i++;
                ?>                <tr <?php
            if ($i % 2 == 0) {
                echo "bgcolor=gray";
            }
                ?>>
                    <td><?php echo ""; ?></td>
                    <td><?php echo ""; ?></td>
                    <td><?php echo ""; ?></td>
                </tr>
            <?php } while ($row = mysql_fetch_array($result)); ?>
            <tfoot>
                <tr bgcolor=gray>
                    <td align="right">
                        Total:
                    </td>
                    <td><?php echo ""; ?></td>
                    <td><?php echo ""; ?></td>
                </tr>
            </tfoot>
我从database里拿出了日期,我想要根据日期来显示资料。但是我以前只会写死的select...
要怎么才能根据database里的变化而增加select的可选项?不想有按了,database没资料显示不出的现象。
所以我不能把全部月份都写下去...

解决方案 »

  1.   

    假如你的数据库结构是这样的id        year(年份)          title(信息标题)
    ---------------------------------------------
    1           2000                 title1
    2           2011                 title2
    3           2011                 title3那么你在提取year的时候只需要这样就可以了
    "Select DISTINCT year(年份) From `表` Order by id desc"
    这样取出的结果是:2000;2011
    把这两个数据放入你的select选项里就好了,绝对不会出现点击了时间之后没有任何数据的状况.
      

  2.   

    怎么我select后,print_r只出现一个月份?我的资料有两个月份啊...怎么做?
    获得两个月份后要循环放进select的option里吗?
      

  3.   

    <select>
       <?php 这里可以循环输出你从数据库中获得的月份 ?>
    </select>
      

  4.   

    我怎么知道我得到的月份是否多过一个...虽说我database里有两个月份。
    但是我print_r()的时候只出现一个啊...
    $result = mysql_query("SELECT DISTINCT * FROM rptguestdaily Order by rpt_date desc");
    我真的有获得到两个吗?
      

  5.   

    SELECT DISTINCT * FROM
    这种写法是错误的,因为DISTINCT是用来取得唯一值的,你看看mysql手册你就明白了另外取出数据来之后你需要用循环输出才行
    例如
    $Rs = Mysql_query("SELECT DISTINCT year FROM 表");
    $row=mysql_fetch_array($Rs);$bb='';
    foreach($row as $aa){
    $bb.=$aa[0];
    }
    echo $bb;
      

  6.   


    <table>
    <?php
    while(条件){
    ?>
    <tr>
    <td>变量内容1</td>
    <td>变量内容2</td>
    </tr>
    <?php
    }
    ?>
    </table>
      

  7.   


    $result = mysql_query("SELECT * FROM rptguestdaily Order by rpt_date desc");
    $row = mysql_fetch_assoc($result);
    $getmonth = strftime("%b", strtotime($row['rpt_date']));<select>
        <?php for($i=0;$i<count($getmonth);$i++){ ?>
        <option value="$getmonth">
            <?php echo $getmonth ?>
        </option>
        <?php } ?>
    </select>
    就算如此我还是得不到两个月份...
      

  8.   

    $row 是个二维数组吧,能这样 $row['rpt_date'] 直接用吗?  你把$row打印一下看是什么结果,贴出来。
      

  9.   

    Array ( [rpt_date] => 2011-06-01 [post_cnt] => 0 [view_cnt] => 3 )
      

  10.   

    你试试 Function View($Sql){
    $Arr=array();
    $i=0;
    $Rs=Mysql_query($Sql) Or Die (Mysql_error()); IF(Mysql_num_rows($Rs)<1){
    Mysql_Free_result($Rs);
    Return $Arr;
    } While($Re=Mysql_fetch_Array($Rs)){
    $Arr[$i++]=$Re;
    }
    Mysql_Free_result($Rs);
    Return $Arr;
    }$_sel='<select><option>選擇項目</option>';
    $Rs=View("SELECT * FROM rptguestdaily Order by rpt_date desc");
    Foreach($Rs as $_s){
    $_sel.='<option>'.$_s[0].'</option>';
    }
    $_sel.='</select>';
    echo $_sel;
    $Rs=NULL;
      

  11.   

    你数据库中只有一条记录.  $getmonth也就是个变量。怎么循环呢?
      

  12.   

    那不然怎么获得database里的所有月份?
    我说过我的database里有三个日期:
    2011-05-30
    2011-05-31
    2011-06-1
      

  13.   


    <?php
    $result=mysql_query("select * from t1 order by time desc");
    while($row=mysql_fetch_assoc($result)){
          $arr[] = strftime("%b", strtotime($row['time']));
    }
    ?>
    <select>
        <?php 
        for($i=0;$i<count($arr);$i++){ 
        ?>
                     <option value="{$arr[$i]}"><?php echo $arr[$i];?></option>
        <?php
        } 
        ?>
    </select>
      

  14.   

    字段写错了,因该这样:<?php
    $result=mysql_query("SELECT * FROM rptguestdaily Order by rpt_date desc");
    while($row=mysql_fetch_assoc($result)){
          $arr[] = strftime("%b", strtotime($row['rpt_date']));
    }
    ?>
    <select>
        <?php 
        for($i=0;$i<count($arr);$i++){ 
        ?>
                   <option value="{$arr[$i]}"><?php echo $arr[$i];?></option>
        <?php
       } 
        ?>
    </select>