|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
小试一下身手,大概是没问题了,那么交给你个任务,做个留言本吧,这和HELLO WORLD有一比啊!^_^,同是新手面临的第一道关。递归|分页|显示 <?php
/*寄存帖子的表布局
CREATE TABLE announce (
announce_id int(11) NOT NULL auto_increment,
board_id smallint(6) NOT NULL,
title varchar(100) NOT NULL,
content tinytext,
add_time datetime DEFAULT '0000-00-00 00:00:00' NOT NULL,
auth_name varchar(20) NOT NULL,
auth_mail varchar(40),
hit_count smallint(6) NOT NULL,
bytes mediumint(9) NOT NULL,
parent_id tinyint(4) NOT NULL,
auth_ip varchar(15) NOT NULL,
top_id int(11) NOT NULL,
return_count tinyint(4) NOT NULL,
face char(3) NOT NULL,
PRIMARY KEY (announce_id),
KEY board_id (board_id),
KEY top_id (top_id)
);
*/
function show_announce($id,$self_id){
global $dbconnect;
global $board_id;
$query="select * from announce where announce_id='$id'";
$result=mysql_query($query,$dbconnect);
$myrow=mysql_fetch_array($result);
mysql_free_result($result);
echo "<li>\n";
echo "<img src='http://www.163design.net/p/b/images/mood".$myrow[face].".gif'> ";
if($self_id!=$id)
echo "<a href='show.php3?board_id=$board_id&announce_id=$myrow[announce_id]&top_id=$myrow[top_id]'>";
echo $myrow[title];
if($self_id!=$id)
echo "</a>";
echo " - <strong>【".$myrow[auth_name]."】</strong> ".$myrow[add_time]." <font color=darkblue>[id:$myrow][announce_id] 点击:$myrow[hit_count]]</font> ($myrow[bytes] Bytes) <font color=red>($myrow[return_count])</font>\n";
$query="select announce_id from announce where parent_id='$id' order by announce_id desc";
$result=mysql_query($query,$dbconnect);
echo "<ul>\n";
while($myrow=mysql_fetch_array($result)){
show_announce($myrow[announce_id],$self_id);
}
echo "</ul>\n";
mysql_free_result($result);
echo "</li>";
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>服装论坛内容</title>
<link rel="stylesheet" type="text/CSS" href="common.css">
</head>
<body>
<?php
//此处需求毗连数据库
//可以依据需求到场分页
$query="select announce_id from announce where top_id='0' order by announce_id desc ";
$result_top=mysql_query($query,$dbconnect);
echo "<ul>\n";
while($myrow_top=mysql_fetch_array($result_top)){
show_announce($myrow_top[announce_id],0);
}
echo "</ul>\n";
mysql_free_result($result_top);
?>
</body>
</html>
刚开始写页面程序,调试完书中的例子。然后就可以尝试编写留言板了, |
|