⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 articlelib.php

📁 1.上传所有文件到你的空间。 2.把数据库文件FORUM.sql导入数据库。 3.修改config.php 和 data文件夹属性为0777。 4.后台管理地址:/admin/login.php
💻 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'>&nbsp;</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 + -