Home php教程 php手册 非递归法实现论坛树型结构及分页!!(心血结晶啊,呵呵)

非递归法实现论坛树型结构及分页!!(心血结晶啊,呵呵)

Jun 21, 2016 am 09:12 AM
gt lt nbsp quot

递归|分页|树型结构

现将本人的实践结果show给大家,不足之处就是分页的方法不太好,不能显示具体的页数,可实在又没有其它更好的解决办法,只好先如此了,如果哪位有类似本论坛的分页方法,表赐教一二,二泉不胜感激!具体可访问我的个人小网站:http://web.nyist.net/~wbgwrq,不废话了,开始吧......

//表的结构如下:
//creat.sql
//简单说明:RootId 论题序数;Layer:帖子层次,缩进的依据;Orders:帖子的顺序
CREATE TABLE over_post (
  id int(11) NOT NULL auto_increment,
  title varchar(80) NOT NULL default '',
  content text,
  postat datetime NOT NULL default '0000-00-00 00:00:00',
  readed int(11) NOT NULL default '0',
  size int(11) NOT NULL default '0',
  rootid int(11) NOT NULL default '0',
  orders int(4) NOT NULL default '0',
  layer int(4) NOT NULL default '0',
  PRIMARY KEY  (id)
) TYPE=MyISAM;
//creat.sql End

//发表根帖,即RootId,Layer,Orders为0的帖子
//said.php
//begin


  
    
      
      
    
    
      
      
    
    
      
    
    
      
    
  

        
你的想法:
        

      

        
      

        
你的内容:
        

      

        
      

      

        

          
          
        

      

  

//said.php End


//帖子内容,且在本页进行跟帖
//content.php
//Begin

$result=mysql_query("select

over_post.title,over_post.content,over_post.postat,over_post.readed,over_post.rootid,over_post.la

yer,over_post.orders from over_post where over_post.id=$id");
$readed=mysql_result($result,0,"readed");
$title=mysql_result($result,0,"title");
$content=mysql_result($result,0,"content");
$date=mysql_result($result,0,"postat");
$rootid=mysql_result($result,0,"rootid");
$orders=mysql_result($result,0,"orders");
$layer=mysql_result($result,0,"layer");
?>

  
   
  
  
     
     
              
   
     
     
   
发表人:
主 题: 》  

Readed:】  
内 容:




  论坛发表跟帖
  

    
      
        
        
      
      
        
        
      
      
        
      
      
        
      
    

          
题目:

        

          
        

          
内容:

        

          
        

        

          

          
          
          
          
          
          

        

//content.php End

//更新数据库
//post.php
//Begin


$content=nl2br(htmlspecialchars($content));
$title=htmlspecialchars($title);        //决不允许在标题上使用html
$date=date("Y-m-d H:i:s");
$length=strlen($content);

if(isset($said))    //发表新帖子
{
$query="insert into over_post

values(null,'$title','$content',$user_id,'$date',0,$length,$img,'','','')";
$result=mysql_query($query) or die(mysql_error());
$r=mysql_query("select max(id) from over_post");
$rootid = mysql_result($r,0)+0;
mysql_query("update over_post set rootid=$rootid where ID=$rootid")or die(mysql_error());
}

if(isset($reply)):    //发表跟帖

mysql_query("update over_post set orders=orders+1 where rootid=$rootid and orders>$orders")or

die(mysql_error());

$layer=$layer+1;
$orders=$orders+1;
$query="insert into over_post

values(null,'$title','$content',$user_id,'$date',0,$length,$img,$rootid,$orders,$layer)";

$result=mysql_query($query) or die(mysql_error());

endif;
     if($result) {
    include"list.php";
}
?>
//post.php End

//重头戏,显示所有帖子,并实现分页
//list.php
//Begin

//找到最新论题的rootid
$query = "select max(rootid) as maxid1, min(rootid) as minid1 from over_post";
$result = mysql_query($query);
$maxid1 = mysql_result($result, 0, "maxid1");
$startid1 = mysql_result($result, 0, "minid1");
if(!($maxid1>0)) $maxid1=0;
if(!($startid1>0)) $startid1=0;
$totalid1 = $maxid1; //这是真正的最大的rootid值, $maxid1要根据$nextmaxid1变的
if($nextmaxid1>0) $maxid1=$nextmaxid1; //翻页

//计算最小rootid:注意下面的desc,与limit结合,保证选取记录的范围.
//如果使用asc, 在mysql_result中检索第0个,将大大错误!
$itemsperpage=30;
$query="select distinct rootid from over_post where rootid
$itemsperpage";
$r=mysql_query($query);
$n=mysql_num_rows($r);
if($n>0) {
  $minid1=mysql_result($r,$n-1);
$query="select * from over_post where rootid=$minid1 order by rootid

desc,orders";
$result=mysql_query($query);
$num=mysql_num_rows($result);

}
else {
  $minid1=0;
  $maxid1=0;
  echo "

没有更多的发言内容
";
}

$query="select distinct rootid from over_post where rootid>$maxid1 order by rootid limit

$itemsperpage";
$r=mysql_query($query);
$n=mysql_num_rows($r);
if($n>0) $up=mysql_result($r,$n-1);
else $up=$totalid1;

$query="select distinct rootid from over_post where rootid
$itemsperpage";
$r=mysql_query($query);
$n=mysql_num_rows($r);
if($n>0) $down=mysql_result($r,0);
else $down=$maxid1;
?>



  
    
      
    
    
      
    
    
      
    
  

href="javascript:window.location.reload()" class=a1>刷新
        首页

上页

        下页  
:$startid1-$totalid1 ";?>
        

echo"
    ";
    while ($array=mysql_fetch_array($result)){
            $id=$array["id"];
            $title=$array["title"];
            $content=$array["content"];
            $postat=$array["postat"];
            $readed=$array["readed"];
            $size=$array["size"];
                if($size==0) $size="无内容";
                    else $size.=" Bytes";
            $rootid=$array["rootid"];
            $orders=$array["orders"];
            $layer=$array["layer"];
                
            $ul="";        //开始树型结构
            $_ul="";
        for($j=0;$j            $ul=$ul."
      ";
                  $_ul=$_ul."
    ";    
                }
    echo $ul."
  • "."$title($size) 【

    ".作者."】 $postat  

    ".$_ul;
    flush();
                    //树型结构结束
    }
    ?>

href="javascript:window.location.reload()" class=a1>刷新
        首页

上页

        下页  
:$startid1-$totalid1 ";?>
        



//list.php End



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)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
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)

Solution: Your organization requires you to change your PIN Solution: Your organization requires you to change your PIN Oct 04, 2023 pm 05:45 PM

The message "Your organization has asked you to change your PIN" will appear on the login screen. This happens when the PIN expiration limit is reached on a computer using organization-based account settings, where they have control over personal devices. However, if you set up Windows using a personal account, the error message should ideally not appear. Although this is not always the case. Most users who encounter errors report using their personal accounts. Why does my organization ask me to change my PIN on Windows 11? It's possible that your account is associated with an organization, and your primary approach should be to verify this. Contacting your domain administrator can help! Additionally, misconfigured local policy settings or incorrect registry keys can cause errors. Right now

How to adjust window border settings on Windows 11: Change color and size How to adjust window border settings on Windows 11: Change color and size Sep 22, 2023 am 11:37 AM

Windows 11 brings fresh and elegant design to the forefront; the modern interface allows you to personalize and change the finest details, such as window borders. In this guide, we'll discuss step-by-step instructions to help you create an environment that reflects your style in the Windows operating system. How to change window border settings? Press + to open the Settings app. WindowsI go to Personalization and click Color Settings. Color Change Window Borders Settings Window 11" Width="643" Height="500" > Find the Show accent color on title bar and window borders option, and toggle the switch next to it. To display accent colors on the Start menu and taskbar To display the theme color on the Start menu and taskbar, turn on Show theme on the Start menu and taskbar

How to change title bar color on Windows 11? How to change title bar color on Windows 11? Sep 14, 2023 pm 03:33 PM

By default, the title bar color on Windows 11 depends on the dark/light theme you choose. However, you can change it to any color you want. In this guide, we'll discuss step-by-step instructions for three ways to change it and personalize your desktop experience to make it visually appealing. Is it possible to change the title bar color of active and inactive windows? Yes, you can change the title bar color of active windows using the Settings app, or you can change the title bar color of inactive windows using Registry Editor. To learn these steps, go to the next section. How to change title bar color in Windows 11? 1. Using the Settings app press + to open the settings window. WindowsI go to "Personalization" and then

OOBELANGUAGE Error Problems in Windows 11/10 Repair OOBELANGUAGE Error Problems in Windows 11/10 Repair Jul 16, 2023 pm 03:29 PM

Do you see "A problem occurred" along with the "OOBELANGUAGE" statement on the Windows Installer page? The installation of Windows sometimes stops due to such errors. OOBE means out-of-the-box experience. As the error message indicates, this is an issue related to OOBE language selection. There is nothing to worry about, you can solve this problem with nifty registry editing from the OOBE screen itself. Quick Fix – 1. Click the “Retry” button at the bottom of the OOBE app. This will continue the process without further hiccups. 2. Use the power button to force shut down the system. After the system restarts, OOBE should continue. 3. Disconnect the system from the Internet. Complete all aspects of OOBE in offline mode

How to enable or disable taskbar thumbnail previews on Windows 11 How to enable or disable taskbar thumbnail previews on Windows 11 Sep 15, 2023 pm 03:57 PM

Taskbar thumbnails can be fun, but they can also be distracting or annoying. Considering how often you hover over this area, you may have inadvertently closed important windows a few times. Another disadvantage is that it uses more system resources, so if you've been looking for a way to be more resource efficient, we'll show you how to disable it. However, if your hardware specs can handle it and you like the preview, you can enable it. How to enable taskbar thumbnail preview in Windows 11? 1. Using the Settings app tap the key and click Settings. Windows click System and select About. Click Advanced system settings. Navigate to the Advanced tab and select Settings under Performance. Select "Visual Effects"

What are the differences between Huawei GT3 Pro and GT4? What are the differences between Huawei GT3 Pro and GT4? Dec 29, 2023 pm 02:27 PM

Many users will choose the Huawei brand when choosing smart watches. Among them, Huawei GT3pro and GT4 are very popular choices. Many users are curious about the difference between Huawei GT3pro and GT4. Let’s introduce the two to you. . What are the differences between Huawei GT3pro and GT4? 1. Appearance GT4: 46mm and 41mm, the material is glass mirror + stainless steel body + high-resolution fiber back shell. GT3pro: 46.6mm and 42.9mm, the material is sapphire glass + titanium body/ceramic body + ceramic back shell 2. Healthy GT4: Using the latest Huawei Truseen5.5+ algorithm, the results will be more accurate. GT3pro: Added ECG electrocardiogram and blood vessel and safety

Display scaling guide on Windows 11 Display scaling guide on Windows 11 Sep 19, 2023 pm 06:45 PM

We all have different preferences when it comes to display scaling on Windows 11. Some people like big icons, some like small icons. However, we all agree that having the right scaling is important. Poor font scaling or over-scaling of images can be a real productivity killer when working, so you need to know how to customize it to get the most out of your system's capabilities. Advantages of Custom Zoom: This is a useful feature for people who have difficulty reading text on the screen. It helps you see more on the screen at one time. You can create custom extension profiles that apply only to certain monitors and applications. Can help improve the performance of low-end hardware. It gives you more control over what's on your screen. How to use Windows 11

10 Ways to Adjust Brightness on Windows 11 10 Ways to Adjust Brightness on Windows 11 Dec 18, 2023 pm 02:21 PM

Screen brightness is an integral part of using modern computing devices, especially when you look at the screen for long periods of time. It helps you reduce eye strain, improve legibility, and view content easily and efficiently. However, depending on your settings, it can sometimes be difficult to manage brightness, especially on Windows 11 with the new UI changes. If you're having trouble adjusting brightness, here are all the ways to manage brightness on Windows 11. How to Change Brightness on Windows 11 [10 Ways Explained] Single monitor users can use the following methods to adjust brightness on Windows 11. This includes desktop systems using a single monitor as well as laptops. let's start. Method 1: Use the Action Center The Action Center is accessible

See all articles