Aşağıdaki işlevi kullanıcı adında bir MySQL tabloya bir yorum eklemek için izin verir "yorum." Daha sonra, dosya "comments2.php" a verilen sunulması için tüm yorumlar görüntülenir.
Bir kullanıcı yorum gönderdiğinde hemen sonra, ben kullanıcı sadece sunulan yorum tarafından demirlemiş edilecek kullanıcının tarayıcısı üst istiyoruz.
Bunu nasıl yapabilirim?
Teşekkür peşin,
John
Fonksiyonu:
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>
';
}
Dosya comments2.php içerir:
$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 tablodaki alanlar "comment":
commentid loginid submissionid comment datecommented