想知道这是一个HTML,PHP或JavaScript问题 [英] want to know whether this is a html, php or javascript issue
问题描述
我想标识每条评论,以便任何成员对评论发表评论时,INSERT和SELECT知道评论的显示位置,评论内容以及评论内容。这就像为每个评论创建一个ID,以便SELECT在每个消息的位置显示每条消息。 BU我不知道这是一个HTML,PHP或JavaScript问题来处理。 jsfiddle的此处。
php
p>我会在url字符串中选择id
$ id = $ _GET [ 'ID']; //这个用户的id在用户表中被评论我想我需要这个id来标识哪个用户被评论为profile,这是他的个人档案的id
if(isset($ _ SESSION ['id' ])){
$ userid = $ _SESSION ['id'];
$ username = $ _SESSION ['name']; }
else {
//做这个
}
//用户标识包含用户注释的用户标识和名称用户登录。
if($ _POST ['comment_field_1']!=){
$ comment_field_1 = $ _POST ['comment_field_1'];
$ comment_field_1 = stripslashes($ comment_field_1);
$ comment_field_1 = strip_tags($ comment_field_1);
$ comment_field_1 = mysql_real_escape_string($ comment_field_1);
$ comment_field_1 = eregi_replace(',',$ comment_field_1);
$ sql = mysql_query(INSERT INTO comments(mem_id,commented_men_id,the_message,parent_id,message_date)
VALUES('$ userid','$ idc','$ comment_field_1',$ parent_id now()))
或die(mysql_error());
//我估计$ parent_id应该初始化为0或1的值,这取决于天气是回应还是评论。
}
// men_id是$ userid的字段,commented_men_id是注释字段,$ idc变量等...
if( $ _POST ['comment_field_2']!=){//响应表单域
$ comment_field_2 = $ _POST ['comment_field_2'];
$ comment_field_2 = stripslashes($ comment_field_2);
$ comment_field_2 = strip_tags($ comment_field_2);
$ comment_field_2 = mysql_real_escape_string($ comment_field_2);
$ comment_field_2 = eregi_replace(',',$ comment_field_2);
$ sql = mysql_query(INSERT INTO comments(mem_id,commented_men_id,the_message,sub_commented_id,message_date)
VALUES('$ userid','$ idc','$ comment_field_1',$ sub_commented_id now()))
或die(mysql_error());
//这里,而不是$ parent_id我使用为响应标记评论而创建的字段,因为响应应该在顶部的某处以0或1的值进行初始化,具体取决于天气是响应还是评论。我不知道天气我应该离开parent_id变量或与这个新字段$ sub_commented_id。你怎么看?
}
// men_id是$ userid的字段,commented_men_id是注释字段,$ idc变量等...
$ b ($ _SESSION ['id'] == $ userid){
$ the_message_form ='
comment(220 char max)
< input class =commentinputname =submittype =buttonvalue =submit commentalign =left/>
< / form>';
$ b $ sql1 = mysql_query(SELECT id,mem_id,commented_men_id,the_message,parent_id,message_date FROM comments WHERE commented_men_id ='$ idc'ORDER BY message_date DESC LIMIT 20)或死(mysql_error());
$ i = 0;
while($ row = mysql_fetch_array($ sql1)){
$ j = $ i ++;
$ message_id = $ row [id];
$ uid = $ row [mem_id];
$ the_message = $ row [the_message];
$ message_date = $ row [message_date];
$ message_date = strftime(%b%d,%Y,%Y%I:%M:%S%p,strtotime($ message_date));
$ sql_mem_data = mysql_query(SELECT id,name FROM users WHERE id ='$ uid'LIMIT 1);
while($ row2 = mysql_fetch_array($ sql_mem_data)){
$ uid = $ row2 [id];
$ ufirstname = $ row2 [name];
$ ufirstname = mb_strimwidth($ ufirstname,0,20,'& hellip;');
$ b $ messageDisplayList。='
< tr>
< td width =autoheight =autobgcolor =#EFEFEFstyle =vertical-align:top>< a width =autoheight =autotitle = '。$ row2 [name]。'href =profile.php?id ='。$ uid。'& name ='。$ row2 [name]。'>'。$ user_pic。 '< / a>< br />
< / td>
< td width =93%bgcolor =#EFEFEF>< a href =profile.php?id ='。$ uid。'>'。 $ ufirstname。 '< / a> &安培;公牛; < span style =font-size:10px; font-weight:bold; color:#A6A6A6;>'。 $ message_date。 '< / span>< br />
< p id =only> '。 $ the_message。 '< / p>< span class =comment>& bull;< a style =padding-left:3.5px; color:#0099ffhref =>评论< / a>< ; / span>< div class =commentForm>< form align =leftid =bringaction =profile.php?id ='。$ uid。'method =postenctype = multipart / form-dataname =message_from>
< textarea name =comment_field_2type =textid =text2rows =3style =width:100%; height:30px;>< / textarea>
< input id =bringinputname =submittype =buttonvalue =submitalign =left/>
< / form>< / div>
< / td>
< / tr>
< / table> <峰; br />;
}
$ sql_sub_coment = mysql_query(SELECT id,mem_id,commented_men_id,sub_commented_id,the_message,message_date FROM comments WHERE sub_commented_id ='$ blabid3'AND sub_commented_id!= 0 ORDER BY blab_date DESC LIMIT 20);
while($ row3 = mysql_fetch_array($ sql_sub_coment)){
$$ message_id3 = $ row3_sub [id];
$ uid3 = $ row3_sub [mem_id];
$ the_message3 = $ row3_sub [the_message];
$ message_date3 = $ row3_sub [message_date];
$ message_date3 = strftime(%b%d,%Y,%Y%I:%M:%S%p,strtotime($ blab_date3));
$ sql_mem_data = mysql_query(SELECT id,name FROM user WHERE id ='$ uid3'LIMIT 1);
while($ row4 = mysql_fetch_array($ sql_mem_data)){
$ uid4 = $ row4 [category_id];
$ ufirstname2 = $ row4 [name];
$ ufirstname2 = mb_strimwidth($ ufirstname2,0,20,'& hellip;');
$ b $ $$ messageDisplayList2。='< table width =100%align =centercellpadding =4bgcolor =#CCCCCCstyle =margin-bottom :0.5em>
< tr>
< td width =autoheight =autobgcolor =#FFFFFF>< a width =autoheight =autotitle ='。row3 [name] ''href =profile.php?category_id ='。$ uid4。'>'。$ blabber_pic2。 '< / a>< br />
< / td>
< td width =93%bgcolor =#EFEFEF>< a href =profile.php?id ='。$ uid4。'>'。 $ ufirstname2。 '< / a> &安培;公牛; < span style =font-size:10px; font-weight:bold; color:#A6A6A6;>'。 $ message_date3。 '< / span>< br />< p id =submessage>'。 $ the_message3。 < / p为H.
< / td>
< / tr>
< / table>';
<!DOCTYPE html PUBLIC - // W3C // DTD XHTML 1.0 Transitional // ENhttp://www.w3.org/TR/ XHTML1 / DTD / XHTML1-transitional.dtd>
< html xmlns =http://www.w3.org/1999/xhtml>
< head>
< meta http-equiv =Content-Typecontent =text / html; charset = utf-8/>
< title>< / title>
< link rel =stylesheethref =style / style.csstype =text / cssmedia =screen/>
< script type =text / javascriptsrc =jquery.js>< / script>
< script type =text / javascript>
$(document.ready)(function(){
$(。commentForm)。hide();
$(。comment)。bind('click',function (){
$(this).nextAll(。commentForm:first)。slideToggle();
return false;
});
var html = $( (); $ b $(。blabinput)。click(function(){
console.log(AJAX EVENT OCCURED)
$ .post($ ('#comment')。attr(action),
$(#comment)。serialize(),
function(html){
// Find (HTML).find('form + table')。insertAfter('#comment')将HTML表单中的第一个表格添加到服务器的HTML表单中,并将其附加到页面上的表单中。 ).after('< br />');
});
});
var html2 = $(#text2)。html() ;
$(。bringinput)。click(function(){
console.log(AJAX EVENT OCCURED)
$ .post($('#bring')。attr (action),
$(#bring)。serialize(),
func (HTML2){
//在服务器的HTML表单后面查找第一个表格,并将其附加到页面上的表单中。 $'
$ b $(html2).find('form + table')。insertAfter('#bring')。after('< br />');
});
});
});
到目前为止,父表单的第一种形式是使用id #message的jquery进行提交和发布,然后第二种形式的id或响应形式的#bring id无法正常工作,它插入但将注释发布到p标签中仅用id,这就是父注释发布的地方,而不是响应评论表单。它应该在下面发布,但不知何故,我有HTML和jQuery的混乱。需要帮助。
评论文字正在滑动切换,但第二次点击时,意味着有时第一次点击它时不会切换。但现在的主要问题是在下面显示响应并在不浏览器刷新的情况下获取Ajaxing。 您需要修改数据库包含您的评论以添加父列的表。顶级评论的父ID为0,这意味着它不是对任何其他评论的回复。
回复将包含顶级评论的ID在修改你的表格后,你需要修改你的PHP代码来识别对顶级注释的响应,并修改你的HTML以适当地显示它们。
。I want to id each comment so that where any member comment on a comment, the INSERT and the SELECT knows where to display the comments, who commented in a comment and in what comment. it is like creating an id for each comment so the SELECT display each message in its place. bu i don't know if it is an html, php or javascript issue to handle. the jsfiddle is here.
php
I do pick the id in the url string
$id = $_GET['id']; // this id of the user being commented in the user table I guess I will need that id to identify which user is being commented "profile" that's the id of his profile
if (isset($_SESSION['id'])) {
$userid = $_SESSION['id'];
$username = $_SESSION['name']; }
else {
// do this
}
// the userid contains the id and name of the user commenting "the user logged in".
if ($_POST['comment_field_1'] != ""){
$comment_field_1 = $_POST['comment_field_1'];
$comment_field_1 = stripslashes($comment_field_1);
$comment_field_1 = strip_tags($comment_field_1);
$comment_field_1 = mysql_real_escape_string($comment_field_1);
$comment_field_1 = eregi_replace("'", "'", $comment_field_1);
$sql = mysql_query("INSERT INTO comments (mem_id,commented_men_id, the_message,parent_id, message_date)
VALUES('$userid','$idc','$comment_field_1', $parent_id now())")
or die (mysql_error());
// i guess the $parent_id should be initialize somewhere in the top with a value of 0 or 1 depending weather it is a response or a comment.
}
// men_id is the field of the $userid, commented_men_id is the field for the commented on, $idc variable etc...
if ($_POST['comment_field_2'] != ""){ // responses form field
$comment_field_2 = $_POST['comment_field_2'];
$comment_field_2 = stripslashes($comment_field_2);
$comment_field_2 = strip_tags($comment_field_2);
$comment_field_2 = mysql_real_escape_string($comment_field_2);
$comment_field_2 = eregi_replace("'", "'", $comment_field_2);
$sql = mysql_query("INSERT INTO comments (mem_id,commented_men_id, the_message,sub_commented_id, message_date)
VALUES('$userid','$idc','$comment_field_1', $sub_commented_id now())")
or die (mysql_error());
// here instead of $parent_id I use field created for responses to tag a comment as a response should be initialize somewhere in the top with a value of 0 or 1 depending weather it is a response or a comment. I am not sure weather I should leave the parent_id variable or come with this new field $sub_commented_id. What do you think?
}
// men_id is the field of the $userid, commented_men_id is the field for the commented on, $idc variable etc...
if (isset($_SESSION['id'])) {
if ($_SESSION['id'] == $userid ) {
$the_message_form = '
comment (220 char max)
<form align="left" id="comment" action="profile.php?id='.$idc.'" method="post" enctype="multipart/form-data" name="message_from">
<textarea type="text" id="text1" name="comment_field_1" rows="3" style="width:97%;"></textarea>
<input class="commentinput" name="submit" type="button" value="submit comment" align="left" />
</form>';
}
}
$sql1 = mysql_query("SELECT id, mem_id, commented_men_id, the_message,parent_id, message_date FROM comments WHERE commented_men_id='$idc' ORDER BY message_date DESC LIMIT 20")or die ( mysql_error () );
$i = 0;
while($row = mysql_fetch_array($sql1)){
$j = $i++;
$message_id = $row["id"];
$uid = $row["mem_id"];
$the_message= $row["the_message"];
$message_date = $row["message_date"];
$message_date = strftime("%b %d, %Y, %Y %I:%M:%S %p", strtotime($message_date));
$sql_mem_data = mysql_query("SELECT id, name FROM users WHERE id='$uid' LIMIT 1");
while($row2 = mysql_fetch_array($sql_mem_data)){
$uid = $row2["id"];
$ufirstname = $row2["name"];
$ufirstname = mb_strimwidth($ufirstname, 0, 20, '…');
}
$messageDisplayList .= '
<table width="100%" align="center" cellpadding="4" bgcolor="#CCCCCC" style="margin-bottom:0.5em">
<tr>
<td width="auto" height="auto" bgcolor="#EFEFEF" style="vertical-align:top"><a width="auto" height="auto" title="'.$row2["name"] .' "href="profile.php?id='.$uid .'&name='.$row2["name"].'">' .$user_pic. '</a><br />
</td>
<td width="93%" bgcolor="#EFEFEF"><a href="profile.php?id='.$uid.'">' . $ufirstname . ' </a> • <span style="font-size:10px; font-weight:bold; color:#A6A6A6;">' . $message_date . '</span><br />
<p id="only"> ' . $the_message . '</p><span class="comment">•<a style="padding-left:3.5px; color:#0099ff" href ="">Comment</a></span><div class="commentForm"><form align="left" id="bring" action="profile.php?id='. $uid .'" method="post" enctype="multipart/form-data" name="message_from">
<textarea name="comment_field_2" type="text" id="text2" rows="3" style="width:100%; height:30px;"></textarea>
<input id="bringinput" name="submit" type="button" value="submit" align="left" />
</form></div>
</td>
</tr>
</table> <br/>';
}
$sql_sub_coment = mysql_query ("SELECT id, mem_id, commented_men_id, sub_commented_id, the_message, message_date FROM comments WHERE sub_commented_id='$blabid3' AND sub_commented_id != 0 ORDER BY blab_date DESC LIMIT 20");
while($row3= mysql_fetch_array($sql_sub_coment)){
$$message_id3 = $row3_sub["id"];
$uid3 = $row3_sub["mem_id"] ;
$the_message3 = $row3_sub["the_message"];
$message_date3 = $row3_sub["message_date"];
$message_date3 = strftime("%b %d, %Y, %Y %I:%M:%S %p", strtotime($blab_date3));
$sql_mem_data = mysql_query("SELECT id, name FROM user WHERE id='$uid3' LIMIT 1");
while($row4 = mysql_fetch_array($sql_mem_data)){
$uid4 = $row4["category_id"];
$ufirstname2 = $row4["name"];
$ufirstname2 = mb_strimwidth($ufirstname2, 0, 20, '…');
}
$$messageDisplayList2 .= '<table width="100%" align="center" cellpadding="4" bgcolor="#CCCCCC" style="margin-bottom:0.5em">
<tr>
<td width="auto" height="auto" bgcolor="#FFFFFF"><a width="auto" height="auto" title="'.$row3["name"] .' "href="profile.php?category_id='.$uid4 .'">' .$blabber_pic2. '</a><br />
</td>
<td width="93%" bgcolor="#EFEFEF"><a href="profile.php?id='.$uid4.'">' . $ufirstname2 . ' </a> • <span style="font-size:10px; font-weight:bold; color:#A6A6A6;">' . $message_date3 . '</span><br /><p id="submessage">' . $the_message3 . '</p>
</td>
</tr>
</table>';
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<link rel="stylesheet" href="style/style.css" type="text/css" media="screen" />
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$(".commentForm").hide();
$(".comment").bind('click', function(){
$(this).nextAll(".commentForm:first").slideToggle();
return false;
});
var html = $("#text1").html();
$(".blabinput").click(function() {
console.log("AJAX EVENT OCCURED")
$.post($('#comment').attr("action"),
$("#comment").serialize(),
function(html) {
// Find the first table after the form in the HTML from the server and append it to the form on the page.
$(html) .find('form + table').insertAfter('#comment').after('<br />');
});
});
var html2 = $("#text2").html();
$(".bringinput").click(function() {
console.log("AJAX EVENT OCCURED")
$.post($('#bring').attr("action"),
$("#bring").serialize(),
function(html2) {
// Find the first table after the form in the HTML from the server and append it to the form on the page.
$(html2) .find('form + table').insertAfter('#bring').after('<br />');
});
});
});
That's what I have so far. the first form the parent form is submitting and posting with the jquery of id #message, then the #bring id for the id of the second form or the response form is not working properly, it is inserting but posting the comment in the p tags with id only., that's where the parent comment post not the response comment form. it should post below but, somehow I have the html and the jquery mess up. Need help in there.
the comment text is sliding toggling but the second time I click on, meaning sometimes it won't toggle the first time I click on it. But the main issue now is getting the responses form displaying below and Ajaxing without browser refresh.
You will need to modify the database table that holds your comments to add a "parent" column. A top-level comment will have a parent ID of 0, meaning it is not a response to any other comment.
Responses will have the ID of the top-level comment in their parent column.
After modifying your table, you will need to modify your PHP code to recognize responses to top-level comments, and modify your HTML to display them appropriately.
这篇关于想知道这是一个HTML,PHP或JavaScript问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!