0
下面的函數允許用戶將註釋插入名爲「註釋」的MySQL表中。然後,文件「comments2.php」顯示給定提交的所有註釋。創建評論錨點
在用戶提交評論之後,我希望用戶瀏覽器的頂部被用戶剛剛提交的評論錨定。
我該怎麼做?
由於提前,
約翰
功能:
function show_commentbox($submissionid, $submission, $url, $submittor, $submissiondate, $countcomments, $dispurl)
{
echo '<form action="http://www...com/.../comments/comments2.php" method="post">
<input type="hidden" value="'.$_SESSION['loginid'].'" name="uid">
<input type="hidden" value="'.$submissionid.'" name="submissionid">
<input type="hidden" value="'.stripslashes($submission).'" name="submission">
<input type="hidden" value="'.$url.'" name="url">
<input type="hidden" value="'.$submittor.'" name="submittor">
<input type="hidden" value="'.$submissiondate.'" name="submissiondate">
<input type="hidden" value="'.$countcomments.'" name="countcomments">
<input type="hidden" value="'.$dispurl.'" name="dispurl">
<label class="addacomment" for="title">Add a comment:</label>
<textarea class="checkMax" name="comment" type="comment" id="comment" maxlength="1000"></textarea>
<div class="commentsubbutton"><input name="submit" type="submit" value="Submit"></div>
</form>
';
}
文件comments2.php包含:
$query = sprintf("INSERT INTO comment VALUES (NULL, %d, %d, '%s', NULL)", $uid, $subid, $comment);
mysql_query($query) or die(mysql_error());
$submissionid = mysql_real_escape_string($_POST['submissionid']);
$submissionid = mysql_real_escape_string($_GET['submissionid']);
$sqlStr = "SELECT comment.comment, comment.datecommented, login.username
FROM comment
LEFT JOIN login ON comment.loginid=login.loginid
WHERE submissionid=$submissionid
ORDER BY comment.datecommented ASC
LIMIT 100";
$tzFrom1 = new DateTimeZone('America/New_York');
$tzTo1 = new DateTimeZone('America/Phoenix');
$result = mysql_query($sqlStr);
$arr = array();
echo "<table class=\"commentecho\">";
$count = 1;
while ($row = mysql_fetch_array($result)) {
$dt1 = new DateTime($row["datecommented"], $tzFrom1);
$dt1->setTimezone($tzTo1);
echo '<tr>';
echo '<td rowspan="3" class="commentnamecount">'.$count++.'.</td>';
echo '<td class="commentname2"><a href="http://www...com/.../members/index.php?profile='.$row["username"].'">'.$row["username"].'</a></td>';
echo '<td rowspan="3" class="commentname1">'.stripslashes($row["comment"]).'</td>';
echo '</tr>';
echo '<tr>';
echo '<td class="commentname2">'.$dt1->format('F j, Y').'</td>';
echo '</tr>';
echo '<tr>';
echo '<td class="commentname2a">'.$dt1->format('g:i a').'</td>';
echo '</tr>';
}
echo "</table>";
在MySQL表中的字段 「註釋」 :
commentid loginid submissionid comment datecommented
我如何獲得紀念品? – John 2010-05-25 04:22:53
另外,如何將評論添加到回覆評論的行? – John 2010-05-25 04:47:06