More Related Content Similar to PHP webboard (20) PHP webboard2. 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 ;
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);
?>
<table width="909" border="1">
<tr>
<th width="99"> <div align="center">QuestionID</div></th>
<th width="458"> <div align="center">Question</div></th>
<th width="90"> <div align="center">Name</div></th>
<th width="130"> <div align="center">CreateDate</div></th>
<th width="45"> <div align="center">View</div></th>
<th width="47"> <div align="center">Reply</div></th>
</tr>
<?
while($objResult = mysql_fetch_array($objQuery))
{
?>
9. Total <?= $Num_Rows;?> Record : <?=$Num_Pages;?> Page :
<?
if($Prev_Page)
{ echo " <a href='$_SERVER[SCRIPT_NAME]?Page=$Prev_Page'><<
Back</a> ";
}
for($i=1; $i<=$Num_Pages; $i++){
if($i != $Page)
{ echo "[ <a href='$_SERVER[SCRIPT_NAME]?Page=$i'>$i</a> ]";
}
else
{ echo "<b> $i </b>";
}
}
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");
}
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);
}
?>
<html>
<body>
<?
//*** 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);
?>
<table width="738" border="1" cellpadding="1" cellspacing="1">
<tr>
<td colspan="2"><center><h1><?=$objResult["Question"];?
></h1></center></td>
</tr>
<tr>
<td height="53" colspan="2"><?=nl2br($objResult["Details"]);?
></td>
</tr>
17. <tr>
<td width="397">Name : <?=$objResult["Name"];?> Create Date : <?
=$objResult["CreateDate"];?></td>
<td width="253">View : <?=$objResult["View"];?> Reply : <?
=$objResult["Reply"];?></td>
</tr>
</table>
<br>
<br>
<?
$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 : <?=$intRows;?>
<table width="738" border="1" cellpadding="1" cellspacing="1">
<tr>
<td height="53" colspan="2"><?=nl2br($objResult2["Details"]);?
></td>
</tr>
<tr>
<td width="397">Name :
<?=$objResult2["Name"];?> </td>
<td width="253">Create Date :
<?=$objResult2["CreateDate"];?></td>
</tr>
</table><br>
19. <?
}
?>
<br>
<a href="Webboard.php">Back to Webboard</a> <br>
<br>
<form action="ViewWebboard.php?QuestionID=<?
=$_GET["QuestionID"];?>&Action=Save" method="post"
name="frmMain" id="frmMain">
<table width="738" border="1" cellpadding="1" cellspacing="1">
<tr>
<td width="78">Details</td>
<td><textarea name="txtDetails" cols="50" rows="5"
id="txtDetails"></textarea></td>
</tr>