一段根据表中日期字段建立的树型目录的代码,有人帮我改成用类来编写吗?
我是一个初学者,对类知道一些,也会用一点,但不知道什么时候可以用,如何发挥好它的作用,所以只有自己搞一段代码,请高手帮我改成用类来编写。
还有我这里只做了年和月,还有具体日子没有加入,改成类的时候,我想也顺利加入这个功能,应该不会太麻烦吧。多谢了!
代码具体如下:
===========
1 require_once('../Connections/notebook.php');//连接数据库文件
1
2mysql_select_db($database_notebook, $notebook);
3$query_year = "SELECT * FROM mydates group by date_format(datetime,'%Y')";//按日期中的年进行分组
4$year = mysql_query($query_year, $notebook) or die(mysql_error());
5$row_year = mysql_fetch_assoc($year);
6$totalRows_year = mysql_num_rows($year);
7
8$numy=$numd=1;
1<script language="JavaScript">
2<!--
3function thisdisplay(n)
4{
5abc = eval(n);
6abct=eval(n+"t");
7if(abc.style.display=="none")
8{
9abc.style.display="";//显示
10abct.src="images/openfold.gif";
11}else{
12abc.style.display="none";//隐藏
13abct.src="images/clsfold.gif";
14}
15}
16//-->
17</script>
1<table bgcolor="#000000" border="0" cellpadding="0" cellspacing="1" width="130">
2<tr>
3<td align="center" bgcolor="#003300" colspan="2"><strong><font color="#FFFFFF" size="4"><em>我的日记</em></font></strong></td>
4</tr>
5<tr>
6<td bgcolor="#FFFFFF">```
7 do {
1 if ($totalRows_year &gt; 0) { // Show if recordset not empty
1
2$thisyear=substr($row_year['datetime'],0,4);//取得年份
3mysql_select_db($database_notebook, $notebook);
4$query_month = "SELECT * FROM mydates where date_format(datetime,'%Y')=".$thisyear." group by date_format(datetime,'%m')";
5$month = mysql_query($query_month, $notebook) or die(mysql_error());
6$row_month = mysql_fetch_assoc($month);
7$totalRows_month = mysql_num_rows($month);
8$numm=1;
1 if ($totalRows_year&gt;$numy){//判断是不是个中最后一个年份,即是否为最后和条记录。
```
echo $thisyear;
```年 |
| |
```
if($totalRows_month>0){
do{
$thismonth=substr($row_month['datetime'],5,2);//取得月份
if($totalRows_month>$numm){
1<table border="0" cellpadding="0" cellspacing="0" width="100%">
2<tr onclick="thisdisplay('```
3 echo y.$thisyear.m.$thismonth;
4```')">
5<td width="35"><img height="17" id="```
6 echo y.$thisyear.m.$thismonth.t;
7```" src="images/clsfold.gif" width="35"/></td>
8<td>```
9 echo $thismonth;
10```月</td>
11</tr>
12</table>
13<table border="0" cellpadding="0" cellspacing="0" id="```
14 echo y.$thisyear.m.$thismonth;
15```" style="display:none" width="100%">
16<tr>
17<td width="51"><img height="17" src="images/line.gif" width="16"/><img height="17" src="images/t.gif" width="16"/><img height="17" src="images/text.gif" width="16"/></td>
18<td>1日</td>
19</tr>
20<tr>
21<td><img height="17" src="images/line.gif" width="16"/><img height="17" src="images/t.gif" width="16"/><img height="17" src="images/text.gif" width="16"/></td>
22<td>2日</td>
23</tr>
24<tr>
25<td><img height="17" src="images/line.gif" width="16"/><img height="17" src="images/turn.gif" width="16"/><img height="17" src="images/text.gif" width="16"/></td>
26<td>10日</td>
27</tr>
28</table>
$numm++;}else{
1
2\---------------------------------------------------------------
3
4<?
5//连接和选择库省略
6$query_year = "SELECT
7YEAR(datetime),
8MONTH(datetime),
9DAYOFMONTH(datetime),
10mydates.* FROM mydates order by datetime";
11$rs = mysql_query($query_year, $notebook) or die(mysql_error());
12
13$oy = $om = $od = 0;
14while(list($y,$m,$d,$id) = mysql_fetch_row($rs)) {
15if($y > $oy) {
16$om = $od = 0;
17$oy = $y;
18$ar[] = array(id=>$y,pid=>0,text=>"{$y}年");
19}
20if($m > $om) {
21$od = 0;
22$om = $m;
23$ar[] = array(id=>sprintf("%d%02d",$y,$m),pid=>$y,text=>"{$m}月");
24}
25if($d > $od) {
26$od = $d;
27$ar[] = array(id=>sprintf("%d%02d%02d",$y,$m,$d),pid=>sprintf("%d%02d",$y,$m),text=>"{$d}日");
28}
29}
30
31include "tree_class.inc.php";
32
33$t = new tree;
34foreach($ar as $v) {
35$t->insert($v);
36}
37$t->display();
38?></td></tr></table></td></tr></table>
Published At
|