I wrote a php+mysql easy to implement the forum in the grading + pagination display routines! (Very detailed Oh!) Although efficiency is not the best, it is not ...

Source: Internet
Author: User
Tags continue empty implement connect mysql query
mysql| Pagination |
/* Store the table structure of the posts------------------------------------------------------

CREATE TABLE Bbsrow (
bbsrow_id Int (6) NOT NULL auto_increment,//posting ID number
Bbsrow_auth varchar NOT NULL,//Post author
Bbsrow_parentid Int (6),//The Father Post ID number of the posting, if the initial sticker is blank
Bbsrow_title varchar NOT NULL,//posts title
Bbsrow_returncount Int (3),//Post number of replies, if no replies are empty
Primary KEY (BBSROW_ID)
);
-----------------------------------------------------------------------------*/


A recursive function that shows the son's post--------------------------------------------------
function Showchildren ($parent _id) {
Global $connect _id;
$query = "SELECT * from Bbsrow where bbsrow_parentid= '". $parent _id. "'";
$result _top=mysql_query ($query, $connect _id);
echo "<ul>\n";
while ($myrow _child=mysql_fetch_row ($result _top)) {
echo "<li>";
echo $myrow _child[0];
echo $myrow _child[1];
echo $myrow _child[2];
echo $myrow _child[3];
Echo $myrow _child[4]. "\ n";
If the reply to the number of stickers is not empty, it means that there is a son posted, continue to show son stickers
if ($myrow _child[4]!= ') {
Showchildren ($myrow _child[0]);
}
}
echo "</ul>";
}
//----------------------------------------------------------------------

Connect the database and put all the starter stickers in the $mainrow array----------------------------

$connect _id=mysql_connect ("localhost", "Test", "test") or Die ("Unable to connect to database");
mysql_select_db ("BBS") or Die ("Cannot select Database");
$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);
//----------------------------------------------------------------------

Start building a paging display------------------------------------------------------

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

$pagesize =10;//The number of initial stickers per page!
$start = $page * $pagesize;
$end = $start + $pagesize;
if ($end > $i) $end = $i;
$totalpage = $i/$pagesize;


$info = "Total". $i. "Records, points". Ceil ($totalpage). "Page, current is paragraph." ($page + 1). "/" . Ceil ($totalpage). "Page <br>\n";
Echo $info;

if ($page >0) $pagestr = "<a href=bbsrow.php4?currentpage=". ($page-1). "> Prev </a>";
$pagestr = $pagestr. "[subsection];

for ($i =0; $i < $totalpage; $i + +) {
if ($i!= $page) {
$pagestr = $pagestr. "<a href=bbsrow.php4?currentpage=". $i. ">". ($i + 1). "</a>";
}
else{
$pagestr = $pagestr. " " . ($i + 1). " ";
}
}

$pagestr = $pagestr. "Page]";

if ($page < $totalpage-1) $pagestr = $pagestr. "<a href=bbsrow.php4?currentpage=". ($page + 1). " > next page </a><p>\n ";

Echo $pagestr;
//----------------------------------------------------------------------

Start Outlining----------------------------------------------------------

echo "<ul>\n";
for ($i = $start; $i < $end; $i + +) {
echo "<li>\n";
echo $mainrow [$i][0];
echo $mainrow [$i][1];
echo $mainrow [$i][2];
echo $mainrow [$i][3];
echo $mainrow [$i][4]. "\ n";
If the reply to the number of stickers is not empty, it means that there is a son posted, continue to show son stickers
if ($mainrow [$i][4]!= ') {
Showchildren ($mainrow [$i][0]);
}
}
echo "</ul>\n";
----------------------------------------------------------------------? >

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.