PHP Webboard
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
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 ;
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 ;
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"];
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";
$objQuery = mysql_query($strSQL); ?> QuestionID Question Name CreateDate View Reply <? while($objResult = mysql_fetch_array($objQuery)) { ?>
"> <? } ?>
Total Record : Page : <? if($Prev_Page) {echo " "; } for($i=1; $i<=$Num_Pages; $i++){ if($i != $Page) {echo "[ $i ]"; } else {echo " $i "; }
if($Page!=$Num_Pages) {echo " Next>> "; } mysql_close(); ?>
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"); }
?> Question Details
Name <? mysql_close(); ?>
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);
//*** 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);
//*** Update View ***// $strSQL = "UPDATE webboard "; $strSQL.="SET View = View + 1 WHERE QuestionID = '".$_GET["QuestionID"]."' "; $objQuery = mysql_query($strSQL); ?>
Name : Create Date : View : Reply : <? $intRows = 0; $strSQL2 = "SELECT * FROM reply WHERE QuestionID = '".$_GET["QuestionID"]."' "; $objQuery2 = mysql_query($strSQL2) or die ("Error Query [".$strSQL."]");
while($objResult2 = mysql_fetch_array($objQuery2)) {$intRows++; ?> No : Name : Create Date :
<? } ?> Back to Webboard &Action=Save" method="post" name="frmMain" id="frmMain"> Details
Name <? mysql_close(); ?>
Include.php <? mysql_connect("localhost","root","1234"); mysql_select_db("test"); ?>