We are doing in the actual process is very simple, I hope we have a good study, to add more functions. This procedure must be run in PHP and MySQL environment. There are three files: comments.php, which is used to display comments, commentadd.php, to process comments, commentform.html to submit comments through from.
1. Establish a database first, and establish a qualifying table if it is established:
CREATE TABLE `comtbl` (
`postID` INT NOT NULL AUTO_INCREMENT ,
`postTITLE` TEXT NOT NULL ,
`posterNAME` TEXT NOT NULL ,
`posterEMAIL` TEXT NOT NULL ,
`postTIME` TIMESTAMP NOT NULL ,
`postTXT` TEXT NOT NULL ,
PRIMARY KEY ( `postID` )
);
Comments View page: comments.php, specific content (with user name and password in the actual work to change):
$dbcnx = mysql_connect("localhost", "username", "password");
mysql_select_db("comments");
Next you need to query the table and sort the IDs by descending:
$result = mysql_query("SELECT * FROM comtbl ORDER BY postID DESC");
if (!$result) {
echo("<b>Error performing query: " . mysql_error() . "</b>");
exit();
}
Here because to read a lot of records, so use the loop to read, the specific procedures are as follows:
while ($row = mysql_fetch_array($result) ) {
$msgTxt = $row["postTXT"];
$msgId = $row["postID"];
$SigName = $row["posterNAME"];
$SigDate = $row["postTIME"];
$msgTitle = $row["postTITLE"];
$url = $row["posterEMAIL"];
Now it's the most critical step, is also a difficult step: because the MySQL ' s TIMESTAMP function is used here (the function can be automatically hungry to add time to a table), and need to get the time of the string, using the String function substr () ($yr for the year, $mo for the month, And so on):
$yr = substr($SigDate, 2, 2);
$mo = substr($SigDate, 4, 2);
$da = substr($SigDate, 6, 2);
$hr = substr($SigDate, 8, 2);
$min = substr($SigDate, 10, 2);
You will also need to extend the functionality of the above code to implement 12 or 24 hour representations or to use AM and PM to represent the previous PM with the following code:
if ($hr > "11") {
$x = "12";
$timetype = "PM";
$hr = $hr - 12;
}else{
$timetype = "AM";
}
In addition, when the reviewer leaves an email, we can set up a person to connect to the implementation link to comment. The code is as follows:
if (!$url) {
$url = "#";
}else{
$stat = $url;
$url = "mailto:" . $url . "";
}