Home Database Mysql Tutorial 用PHP+MYSQL 实现论坛里的分级+分页显示_MySQL

用PHP+MYSQL 实现论坛里的分级+分页显示_MySQL

Jun 01, 2016 pm 02:04 PM
echo p Grading accomplish show forum


/*存放贴子的表结构------------------------------------------------------

create table bbsrow(
bbsrow_id int(6) not null auto_increment, //贴子ID号
bbsrow_auth varchar(20) not null, //贴子作者
bbsrow_parentid int(6), //贴子的父亲贴子ID号,如为首发贴则为空
bbsrow_title varchar(200) not null, //贴子标题
bbsrow_returncount int(3), //贴子的回复贴数,如果没有回贴则为空
primary key (bbsrow_id)
);
-----------------------------------------------------------------------------*/


//显示儿子贴的递归函数--------------------------------------------------
function showchildren($parent_id){
global $connect_id;
$query="select * from bbsrow where bbsrow_parentid='" . $parent_id . "'";
$result_top=mysql_query($query,$connect_id);
echo "
    \n";
    while($myrow_child=mysql_fetch_row($result_top)){
    echo "
  • ";
    echo $myrow_child[0];
    echo $myrow_child[1];
    echo $myrow_child[2];
    echo $myrow_child[3];
    echo $myrow_child[4] . "\n";
    //如果回复贴数不为空,则表示有儿子贴,继续显示儿子贴
    if($myrow_child[4]!=''){
    showchildren($myrow_child[0]);
    }
    }
    echo "
";
}
//----------------------------------------------------------------------

//连接数据库并将所有首发贴放到$mainrow数组里----------------------------

$connect_id=mysql_connect("localhost","test","test") or die("无法连接数据库");
mysql_select_db("bbs") or die("无法选择数据库");
$query="select * from bbsrow where bbsrow_parentid=''";
$result=mysql_query($query,$connect_id);

$i=0;
while($myrow=mysql_fetch_row($result)) {
$mainrow[$i][0]=$myrow[0];
$mainrow[$i][1]=$myrow[1];
$mainrow[$i][2]=$myrow[2];
$mainrow[$i][3]=$myrow[3];
$mainrow[$i][4]=$myrow[4];
$i++;
}
mysql_free_result($result);
//----------------------------------------------------------------------

//开始构建分页显示------------------------------------------------------

if($currentpage!=""){
$page=$currentpage;
}
else{
$page=0;
}

$pagesize=10;//每页显示的首发贴数!
$start=$page*$pagesize;
$end=$start+$pagesize;
if($end>$i) $end=$i;
$totalpage=$i/$pagesize;


$info=" 共有" . $i . "条纪录,分" . ceil($totalpage) . "页,当前为第" . ($page+1) . "/" . ceil($totalpage) . "页
\n";
echo $info;

if($page>0) $pagestr="上一页";
$pagestr=$pagestr . " [第 ";

for($i=0;$iif($i!=$page){
$pagestr=$pagestr . " " . ($i+1) . " ";
}
else{
$pagestr=$pagestr . " " . ($i+1) . " ";
}
}

$pagestr=$pagestr . "页]";

if($page下一页

\n";

echo $pagestr;
//----------------------------------------------------------------------

//开始分级显示----------------------------------------------------------

echo "

    \n";
    for($i=$start;$iecho "
  • \n";
    echo $mainrow[$i][0];
    echo $mainrow[$i][1];
    echo $mainrow[$i][2];
    echo $mainrow[$i][3];
    echo $mainrow[$i][4] . "\n";
    //如果回复贴数不为空,则表示有儿子贴,继续显示儿子贴
    if($mainrow[$i][4]!=''){
    showchildren($mainrow[$i][0]);
    }
    }
    echo "
\n";
//----------------------------------------------------------------------?>

摘自:http://www.chinaasp.com/columns/php/article1367.asp
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to implement dual WeChat login on Huawei mobile phones? How to implement dual WeChat login on Huawei mobile phones? Mar 24, 2024 am 11:27 AM

How to implement dual WeChat login on Huawei mobile phones? With the rise of social media, WeChat has become one of the indispensable communication tools in people's daily lives. However, many people may encounter a problem: logging into multiple WeChat accounts at the same time on the same mobile phone. For Huawei mobile phone users, it is not difficult to achieve dual WeChat login. This article will introduce how to achieve dual WeChat login on Huawei mobile phones. First of all, the EMUI system that comes with Huawei mobile phones provides a very convenient function - dual application opening. Through the application dual opening function, users can simultaneously

PHP Programming Guide: Methods to Implement Fibonacci Sequence PHP Programming Guide: Methods to Implement Fibonacci Sequence Mar 20, 2024 pm 04:54 PM

The programming language PHP is a powerful tool for web development, capable of supporting a variety of different programming logics and algorithms. Among them, implementing the Fibonacci sequence is a common and classic programming problem. In this article, we will introduce how to use the PHP programming language to implement the Fibonacci sequence, and attach specific code examples. The Fibonacci sequence is a mathematical sequence defined as follows: the first and second elements of the sequence are 1, and starting from the third element, the value of each element is equal to the sum of the previous two elements. The first few elements of the sequence

How to implement the WeChat clone function on Huawei mobile phones How to implement the WeChat clone function on Huawei mobile phones Mar 24, 2024 pm 06:03 PM

How to implement the WeChat clone function on Huawei mobile phones With the popularity of social software and people's increasing emphasis on privacy and security, the WeChat clone function has gradually become the focus of people's attention. The WeChat clone function can help users log in to multiple WeChat accounts on the same mobile phone at the same time, making it easier to manage and use. It is not difficult to implement the WeChat clone function on Huawei mobile phones. You only need to follow the following steps. Step 1: Make sure that the mobile phone system version and WeChat version meet the requirements. First, make sure that your Huawei mobile phone system version has been updated to the latest version, as well as the WeChat App.

Discuz Forum Permission Management: Read Permission Setting Guide Discuz Forum Permission Management: Read Permission Setting Guide Mar 10, 2024 pm 05:33 PM

Discuz forum permission management: Read the permission setting guide In Discuz forum management, permission setting is a crucial part. Among them, the setting of reading permissions is particularly important, as it determines the scope of content that different users can see in the forum. This article will introduce in detail the reading permission settings of the Discuz forum and how to flexibly configure it for different needs. 1. Basic concepts of reading permissions In the Discuz forum, reading permissions mainly include the following concepts that need to be understood: Default reading permissions: Default after new user registration

Master how Golang enables game development possibilities Master how Golang enables game development possibilities Mar 16, 2024 pm 12:57 PM

In today's software development field, Golang (Go language), as an efficient, concise and highly concurrency programming language, is increasingly favored by developers. Its rich standard library and efficient concurrency features make it a high-profile choice in the field of game development. This article will explore how to use Golang for game development and demonstrate its powerful possibilities through specific code examples. 1. Golang’s advantages in game development. As a statically typed language, Golang is used in building large-scale game systems.

PHP Game Requirements Implementation Guide PHP Game Requirements Implementation Guide Mar 11, 2024 am 08:45 AM

PHP Game Requirements Implementation Guide With the popularity and development of the Internet, the web game market is becoming more and more popular. Many developers hope to use the PHP language to develop their own web games, and implementing game requirements is a key step. This article will introduce how to use PHP language to implement common game requirements and provide specific code examples. 1. Create game characters In web games, game characters are a very important element. We need to define the attributes of the game character, such as name, level, experience value, etc., and provide methods to operate these

Go language development essentials: 5 popular framework recommendations Go language development essentials: 5 popular framework recommendations Mar 24, 2024 pm 01:15 PM

"Go Language Development Essentials: 5 Popular Framework Recommendations" As a fast and efficient programming language, Go language is favored by more and more developers. In order to improve development efficiency and optimize code structure, many developers choose to use frameworks to quickly build applications. In the world of Go language, there are many excellent frameworks to choose from. This article will introduce 5 popular Go language frameworks and provide specific code examples to help readers better understand and use these frameworks. 1.GinGin is a lightweight web framework with fast

Samsung will provide displays for Microsoft's MR headsets, and the devices are expected to be lighter and have clearer displays Samsung will provide displays for Microsoft's MR headsets, and the devices are expected to be lighter and have clearer displays Aug 10, 2024 pm 09:45 PM

Recently, Samsung Display and Microsoft signed an important cooperation agreement. According to the agreement, Samsung Display will develop and supply hundreds of thousands of OLEDoS panels for mixed reality (MR) head-mounted devices to Microsoft. Microsoft is developing an MR device for multimedia content such as games and movies. This device is expected to It will be launched after the OLEDoS specifications are finalized, mainly serving the commercial field, and is expected to be delivered as early as 2026. OLEDoS (OLED on Silicon) technology OLEDoS is a new display technology that deposits OLED on a silicon substrate. Compared with traditional glass substrates, it is thinner and has higher pixels. OLEDoS display and ordinary display

See all articles