If you have any questions please contact me: http://www.webjx.com web@webjx.com
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 handle comments, and 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:
The following is the specific commentform.html code, which allows comments to be made by the author, and then submits the data online by submitting the data to the commentadd.php.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service