开发者

Appending Comment Number Anchors to Comments

开发者 https://www.devze.com 2022-12-31 18:09 出处:网络
I am using a PHP file called c开发者_JS百科omments.php that has a query that enters values into a mySQL table called \"comment.\"As the query does this, it auto-generates a field called \"commentid\",

I am using a PHP file called c开发者_JS百科omments.php that has a query that enters values into a mySQL table called "comment." As the query does this, it auto-generates a field called "commentid", which is set to auto_increment in MySQL. The file also contains a loop what echoes out all comments for a given submission.

It all works fine and dandy, but I want to simultaneously pull this "commentid" and turn it into a hashtag / anchor that when appended to the end of the URL makes that comment at the top of the user's browser.

Someone said on another question that in order to do this one thing I should do is create an anchor on the row where the comment is being printed out. How can I do this?

Thanks in advance,

John

The query that inserts comments into the MySQL table "comment":

$query = sprintf("INSERT INTO comment VALUES (NULL, %d, %d, '%s', NULL)", $uid, $subid, $comment);

mysql_query($query) or die(mysql_error());

The fields in the table "comment":

commentid loginid submissionid comment datecommented

The row in a loop where the comments are echoed out:

echo '<td rowspan="3" class="commentname1">'.stripslashes($row["comment"]).'</td>';


If you're concerned with standards, use ID as this is more portable code and make sure you start the value of id with a letter, not a number:

echo '<td rowspan="3" class="commentname1" id="comment' . $row["commentid"] . '">'.stripslashes($row["comment"]).'</td>';


echo '<td rowspan="3" class="commentname1"><a name="'.$row["commentid"].'"/>'.stripslashes($row["comment"]).'</td>';
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号