?? articlelib.php
字號:
<?php
//articlelib.php 在article子目錄下
require "lib.php";
$db = db_connect();
//返回論壇中所有文章的數目
function readnum()
{
global $db;
$sql = "select id from article where id>0";
$result = mysql_query($sql, $db);
$total = mysql_num_rows($result);
return $total;
}
//返回論壇中所有parent字段值為0的記錄(一級父)
function readborder_parent()
{
global $db;
$sql = "select id,title,importtime,content,writer,click,adda,fl from article where parent='0' order by id desc";
$result = mysql_query($sql, $db) or db_error();
if ($result)
{
return $result;
}
else
{
return "";
}
}
//這里用到了兩個數組,$infocontent_child, $infofamily_child
//$infocontent_child用來存儲對應于一個一級父下的所有子文章
//infofamily_child用來存儲這些文章之間的關系,如0表示一級父、1表示二級父、2表示三級父
//依次類推。以方便顯示文章之間的關系
//返回對應于一級父下的所有子文章和這些文章的內在聯系
$infocontent_child;
$infofamily_child;
function readborder_child($parent, $arragement)
{
global $db;
global $infocontent_child;
global $infofamily_child;
$sql = "select id,title,importtime,writer,content,click,adda,fl from article where parent='$parent' order by id desc";
$result = mysql_query($sql, $db) or db_error();
if ($result)
{
$i = 0;
while ($resarticle=mysql_fetch_array($result))
{
$nums = count($infocontent_child);
$infocontent_child[$nums] = $resarticle;
$nums = count($infofamily_child);
$infofamily_child[$nums] = $arragement;
if ($resarticle["id"] > 0)
{
$i++;
$parent = $resarticle["id"];
readborder_child($parent, $arragement+$i);
//遞歸調用
}
}
}
}
//這里用到了兩個數組:$info_content, $info_family
//$info_content用來存儲論壇所有的文章信息
//$info_family用來存儲文章之間的關系
//該函數返回論壇中所有的文章,以及這些文章之間的關系
$info_content;
$info_family;
function readborder_all()
{
global $infocontent_child;
global $infofamily_child;
global $info_content;
global $info_family;
global $begin;
if (empty($begin))
{
$begin = 0;
}
$result_parent = readborder_parent();
//讀出所有的一級父
if (!empty($result_parent))
{
while ($resarticle_parent = mysql_fetch_array($result_parent))
{
if ($resarticle_parent["id"] > 0)
{
//找出每一個一級父,再找出其所有與之關聯的實體
$info_content[] = $resarticle_parent;
//一級父的info_family為0
$info_family[] = 0;
readborder_child($resarticle_parent["id"], 1);
if (is_array($infocontent_child) && is_array($infofamily_child))
{
$nums = count($infocontent_child);
for ($i=$begin; $i<$nums; $i++)
{
$info_content[] = $infocontent_child[$i];
$info_family[] = $infofamily_child[$i];
}
$begin = $nums;
}
}
}
}
}
//搜索文章可以按標題、內容、作者、時間等四種方式進行
//返回文章搜索的結果
function search_forum($style_search, $text_search)
{
global $db;
$sql = "select id,title,content,click,writer,importtime,adda,fl from article where ";
if ($text_search != "")
{
if ($style_search == "title")
{
$sql = $sql."title like '%$text_search%'";
}
if ($style_search == "content")
{
$sql = $sql."content like '%$text_search%'";
}
if ($style_search == "writer")
{
$sql = $sql."writer like '%$text_search%'";
}
if ($style_search == "fl")
{
$sql = $sql."fl like '%$text_search%'";
}
}
$result = mysql_query($sql, $db) or db_error();
if ($result)
{
return $result;
}
}
//用于將發表(或回復)的文章寫入數據庫中
function write_card($title, $content, $writer, $parent, $adda,$fl)
{
global $db;
if ($title != "")
{
//String_dowith, text_dowith分別調用了以前的函數
$title = string_dowith($title);
$content = text_dowith($content);
$importtime = date("Y-m-d H:i:s");
$click = 1;
$sql = "insert into article ";
$sql = $sql."(title,content,importtime,writer,click,parent,adda,fl)";
$sql = $sql." values('$title','$content','$importtime','$writer','$click','$parent','$adda','$fl')";
$result = mysql_query($sql, $db) or db_error();
}
}
function update_click($id)
{
global $db;
$sql = "update article set click=click+1 where id='$id'";
$result = mysql_query($sql, $db) or db_error();
}
function pri_page($formname, $fll, $nowpage, $num_page)
{
$nextpage=$nowpage+1;
$rewpage=$nowpage-1;
echo "<TABLE>";
echo "<TBODY>";
echo "<TR>";
echo "<TD width='50%' height='15'> </TD>";
echo "<TD width='10%' height='15'>";
echo "<DIV align='center'>";
if ($nowpage <= 1)
{
echo "首頁</A>";
}
else
{
echo "<A href='..'>首頁</A>";
}
echo "</DIV>";
echo "</TD>";
echo "<TD width='10%' height='15'>";
echo "<DIV align='center'>";
if ($nowpage <= 1)
{
echo "|上一頁";
}
else
{
echo "<A href='$formname.php?nowpage=$rewpage&fll=$fll'>|上一頁</A>";
}
echo "</DIV>";
echo "</TD>";
echo "<TD width='10%' height='15'>";
echo "<DIV align='center'>";
echo "$nowpage/$num_page";
echo "</DIV>";
echo "</TD>";
echo "<TD width='10%' height='15'>";
echo "<DIV align='center'>";
if ($nowpage >= $num_page)
{
echo "|下一頁";
}
else
{
echo "<A href='$formname.php?nowpage=$nextpage&fll=$fll'>|下一頁</A>";
}
echo "</DIV>";
echo "</TD>";
echo "<TD width='10%' height='15'>";
echo "<DIV align='center'>";
if ($nowpage >= $num_page)
{
echo "結尾頁";
}
else
{
echo "<A href='$formname.php?nowpage=$num_page'>|結尾頁</A>";
}
echo "</DIV>";
echo "</TD>";
echo "</TR>";
echo "</TBODY>";
echo "</TABLE>";
}
?>
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -