Home >Backend Development >PHP Tutorial > 浅析经典的PHP论坛程序是怎么写成的
浅析经典的PHP论坛程序是如何写成的?
作为一个论坛程序爱好者,趁空闲时间写一下编写论坛的心得。
以自己编写的开源论坛为例,开发重点是在第一步,如何排列出版块,写出这个,接下去就比较顺手了。
版块分为大版块,下面有各个小版块,小版块下面可能还有子版块。为了减少难度,子版块部分忽略不谈。
设计库设计分为2张表
大版块2个字段
id => 主键
bzone =>大版块名称
小版块5个字段
id => 主键
szone => 小版块名称
mark => 小版块说明文字
bid => 大版块ID,对应大版块的主键
ssort => 小版块排序,可以以小版块影响大版块的排序
以这2张表的设计就能够全部搞定论坛版块的功能部分?答案是肯定的
代码实现
$sql_block = "select * from " . C('db_prefix') . "small_block order by ssort desc,bid desc,szone desc";<br> $query_block = mysql_query($sql_block);<br> $data_block = array();<br> $data_big = array();<br> $time1 = date("Y-m-d");<br> $time1 .= " 00:00:00";<br> $time2 = date("Y-m-d");<br> $time2 .= " 23:59:59";<br> while ($arr_block = mysql_fetch_array($query_block)) {<br> $data_block[] = $arr_block;<br> <br> $bsql = "select * from " . C('db_prefix') . "big_block where id=" . $arr_block['bid'];<br> $barr = mysql_fetch_array(mysql_query($bsql));<br> $data_big[$arr_block['bid']] = $barr['bzone'];<br> <br> ${'zhuti' . $arr_block['id']} = mysql_num_rows(mysql_query("select * from " . C('db_prefix') . "talk where parentid=" . $arr_block['id']));<br> $this->assign("zhuti" . $arr_block['id'], ${'zhuti' . $arr_block['id']});<br> <br> ${'tiezi1' . $arr_block['id']} = mysql_num_rows(mysql_query("select * from " . C('db_prefix') . "talk where parentid=" . $arr_block['id']));<br> ${'tiezi2' . $arr_block['id']} = mysql_num_rows(mysql_query("select * from " . C('db_prefix') . "reply where parentid2=" . $arr_block['id']));<br> ${'tiezi' . $arr_block['id']} = ${'tiezi1' . $arr_block['id']} + ${'tiezi2' . $arr_block['id']}; <div class="clear"> </div>