1 / 21

PHP Webboard

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` (

yeo-butler
Télécharger la présentation

PHP Webboard

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. PHPWebboard

  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 <html> <body> <a href="NewQuestion.php">New Topic</a> <? 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); ?> <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)) { ?>

  8. <tr> <td><div align="center"><?=$objResult["QuestionID"];?></div></td> <td><a href= "ViewWebboard.php?QuestionID=<?=$objResult["QuestionID"];?>"> <?=$objResult["Question"];?></a></td> <td><?=$objResult["Name"];?></td> <td><div align="center"><?=$objResult["CreateDate"];?></div></td> <td align="right"><?=$objResult["View"];?></td> <td align="right"><?=$objResult["Reply"];?></td> </tr> <? } ?> </table> <br>

  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>"; } }

  10. if($Page!=$Num_Pages) { echo " <a href = '$_SERVER[SCRIPT_NAME]?Page=$Next_Page'>Next>></a> "; } mysql_close(); ?> </body> </html>

  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. ?> <html> <body> <form action="NewQuestion.php?Action=Save" method="post“ name="frmMain" id="frmMain"> <table width="621" border="1" cellpadding="1" cellspacing="1"> <tr> <td>Question</td> <td><input name="txtQuestion" type="text" id="txtQuestion" value="" size="70"></td> </tr> <tr> <td width="78">Details</td> <td><textarea name="txtDetails" cols="50" rows="5" id="txtDetails"></textarea></td> </tr>

  13. <tr> <td width="78">Name</td> <td width="647"><input name="txtName" type="text" id="txtName" value="" size="50"></td> </tr> </table> <input name="btnSave" type="submit" id="btnSave" value="Submit"> </form> </body> </html> <? 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); } ?> <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>

  20. <tr> <td width="78">Name</td> <td width="647"><input name="txtName" type="text" id="txtName" value="" size="50"></td> </tr> </table> <input name="btnSave" type="submit" id="btnSave" value="Submit"> </form> </body> </html> <? mysql_close(); ?>

  21. Include.php <? mysql_connect("localhost","root","1234"); mysql_select_db("test"); ?>

More Related