$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 2000 title1
2 2011 title2
3 2011 title3那么你在提取year的时候只需要这样就可以了
"Select DISTINCT year(年份) From `表` Order by id desc"
这样取出的结果是:2000;2011
把这两个数据放入你的select选项里就好了,绝对不会出现点击了时间之后没有任何数据的状况.
获得两个月份后要循环放进select的option里吗?
<?php 这里可以循环输出你从数据库中获得的月份 ?>
</select>
但是我print_r()的时候只出现一个啊...
$result = mysql_query("SELECT DISTINCT * FROM rptguestdaily Order by rpt_date desc");
我真的有获得到两个吗?
这种写法是错误的,因为DISTINCT是用来取得唯一值的,你看看mysql手册你就明白了另外取出数据来之后你需要用循环输出才行
例如
$Rs = Mysql_query("SELECT DISTINCT year FROM 表");
$row=mysql_fetch_array($Rs);$bb='';
foreach($row as $aa){
$bb.=$aa[0];
}
echo $bb;
<table>
<?php
while(条件){
?>
<tr>
<td>变量内容1</td>
<td>变量内容2</td>
</tr>
<?php
}
?>
</table>
$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>
就算如此我还是得不到两个月份...
$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;
我说过我的database里有三个日期:
2011-05-30
2011-05-31
2011-06-1
<?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>
$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>