Download presentation
Presentation is loading. Please wait.
Published byAllen Miller Modified over 9 years ago
1
PHP Webboard
2
Tables and files 2 Tables(Webboard and Reply) Webboard.php for show all question NewQuestion.php for creating new question ViewWebboard.php for show question,replies and create new reply And include.php for connect database
3
CREATE TABLE Webboard CREATE TABLE `webboard` ( `QuestionID` int(5) unsigned zerofill NOT NULL auto_increment, `CreateDate` datetime NOT NULL, `Question` varchar(255) NOT NULL, `Details` text NOT NULL, `Name` varchar(50) NOT NULL, `View` int(5) NOT NULL, `Reply` int(5) NOT NULL, PRIMARY KEY (`QuestionID`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
4
CREATE TABLE Reply CREATE TABLE `reply` ( `ReplyID` int(5) unsigned zerofill NOT NULL auto_increment, `QuestionID` int(5) unsigned zerofill NOT NULL, `CreateDate` datetime NOT NULL, `Details` text NOT NULL, `Name` varchar(50) NOT NULL, PRIMARY KEY (`ReplyID`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
5
Webboard.php New Topic <? include ("include.php"); $strSQL = "SELECT * FROM webboard "; $objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]"); $Num_Rows = mysql_num_rows($objQuery); $Per_Page = 10; // Per Page $Page = $_GET["Page"];
6
if(!$_GET["Page"]) {$Page=1;} $Prev_Page = $Page-1; $Next_Page = $Page+1; $Page_Start = (($Per_Page*$Page)-$Per_Page); if($Num_Rows<=$Per_Page) {$Num_Pages =1;} else if(($Num_Rows % $Per_Page)==0) {$Num_Pages =($Num_Rows/$Per_Page) ;} else {$Num_Pages =($Num_Rows/$Per_Page)+1; $Num_Pages = (int)$Num_Pages; } $strSQL.=" order by QuestionID DESC LIMIT $Page_Start, $Per_Page";
7
$objQuery = mysql_query($strSQL); ?> QuestionID Question Name CreateDate View Reply <? while($objResult = mysql_fetch_array($objQuery)) { ?>
8
"> <? } ?>
9
Total Record : Page : <? if($Prev_Page) {echo " "; } for($i=1; $i<=$Num_Pages; $i++){ if($i != $Page) {echo "[ $i ]"; } else {echo " $i "; }
10
if($Page!=$Num_Pages) {echo " Next>> "; } mysql_close(); ?>
11
NewQuestion.php <? include ("include.php"); if($_GET["Action"] == "Save") {//*** Insert Question ***// $strSQL = "INSERT INTO webboard "; $strSQL.="(CreateDate,Question,Details,Name) "; $strSQL.="VALUES "; $strSQL.="('".date("Y-m-d H:i:s")."','".$_POST["txtQuestion"]."','".$_POST["txtDetails"]."','".$_ POST["txtName"]."') "; $objQuery = mysql_query($strSQL); header("location:Webboard.php"); }
12
?> Question Details
13
Name <? mysql_close(); ?>
14
ViewWebboard.php <? include ("include.php"); if($_GET["Action"] == "Save") {//*** Insert Reply ***// $strSQL = "INSERT INTO reply "; $strSQL.="(QuestionID,CreateDate,Details,Name) "; $strSQL.="VALUES "; $strSQL.="('".$_GET["QuestionID"]."','".date("Y-m-d H:i:s")."','".$_POST["txtDetails"]."','".$_POST["txtName"]."') "; $objQuery = mysql_query($strSQL);
15
//*** Update Reply ***// $strSQL = "UPDATE webboard "; $strSQL.="SET Reply = Reply + 1 WHERE QuestionID = '".$_GET["QuestionID"]."' "; $objQuery = mysql_query($strSQL); } ?> <? //*** Select Question ***// $strSQL = "SELECT * FROM webboard WHERE QuestionID = '".$_GET["QuestionID"]."' "; $objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]"); $objResult = mysql_fetch_array($objQuery);
16
//*** Update View ***// $strSQL = "UPDATE webboard "; $strSQL.="SET View = View + 1 WHERE QuestionID = '".$_GET["QuestionID"]."' "; $objQuery = mysql_query($strSQL); ?>
17
Name : Create Date : View : Reply : <? $intRows = 0; $strSQL2 = "SELECT * FROM reply WHERE QuestionID = '".$_GET["QuestionID"]."' "; $objQuery2 = mysql_query($strSQL2) or die ("Error Query [".$strSQL."]");
18
while($objResult2 = mysql_fetch_array($objQuery2)) {$intRows++; ?> No : Name : Create Date :
19
<? } ?> Back to Webboard &Action=Save" method="post" name="frmMain" id="frmMain"> Details
20
Name <? mysql_close(); ?>
21
Include.php <? mysql_connect("localhost","root","1234"); mysql_select_db("test"); ?>
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.