2010-05-25 86 views
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 

回答

1

是的。将评论提交给数据库时,请获取存储评论的commentid。转发用户到http://whatever/comments_page?query_string# < commentid>。

然后,在显示注释的页面中,将“id”属性添加到与用户注释相对应的行中,值为commentid

+0

我如何获得纪念品? – John 2010-05-25 04:22:53

+0

另外,如何将评论添加到回复评论的行? – John 2010-05-25 04:47:06