[FIXED link]How to show ajax data correctly when it include in a php mysql query?

Discussion in 'JavaScript' started by cj333, Jan 31, 2011.

  1. #1
    I want to add a comment system after my article, <form id="postform" class="postform"> is written into a MYSQL_QUERY result circle. but after post a comment, the current posted comment will be showed in all the <div class="post_comment"></div>.
    how to modify jquery ajax part so that the current posted comment only be showed in its own <div class="post_comment"></div>? Thanks.

    jquery ajax part
    
    $(document).ready(function(){
    $(".Submit").click(function(){
    var title    = $(this).closest('form').find("#title").val();
    var content   = $(this).closest('form').find("#content").val();
    $.ajax({
    type: "POST",
    url: "ajax_post.php",
    data: {title:title,content:content},
    success: function(date_added){
    if(date_added != 0)
    {
    var structure = '<div class="comment_date_added">'+date_added+'</div><div class="comment_content">'+content+'</div>';        
    $(".post_comment").prepend(structure);
    }
    }
    });
    });
    });
    
    Code (markup):
    PHP part
    <?php
    ...
    while($result = mysql_fetch_array($resultset))
    {
    $article_title = $result['article_title'];
    ...
    ?>
    <form id="postform" class="postform">
    <input type="hidden" name="title" id="title" value="<?=$article_title;?>" />
    <input type="text" name="content" id="content" />
    <input type="button" value="Submit" class="Submit" />
    </form>
    <div class="post_comment">
    <?php
    $resultSet = @mysql_query("select * from customcomment where article='".$article_title."' order by date_added desc");
    while($resultRow = mysql_fetch_array($resultSet))
    {
    $date_added = $resultRow['date_added'];
    $comment = stripslashes($resultRow['content']);
    ?>
    <div class="comment_date_added"><?=$date_added;?></div><div class="comment_content"><?=$comment;?></div>
    <?php
    }
    ?>
    </div>
    Code (markup):
    For my poor English, may be not write clearly, this is the first two article's html code output from the php mysql query circle.
    <div class="articlewarp">
    <div class="articlecontent">
    <!--first article content-->
    </div>
    <form id="postform" class="postform">
    <input type="hidden" name="title" id="title" value="first article title" />
    <input type="text" name="content" id="content" />
    <input type="button" value="Submit" class="Submit" />
    </form>
    <div class="post_comment">
    <!-- if this div.postform submit, the current posted comment will be showed in here -->
    <div class="comment_date_added">Monday 31 January 2011, 3:58 pm</div>
    <div class="comment_content">aaa</div>
    </div>
    </div><!--first  div.articlewarp end-->
    
    <div class="articlewarp">
    <div class="articlecontent">
    <!--second article content-->
    </div>
    <form id="postform" class="postform">
    <input type="hidden" name="title" id="title" value="second article title" />
    <input type="text" name="content" id="content" />
    <input type="button" value="Submit" class="Submit" />
    </form>
    <div class="post_comment">
    <!-- if this div.postform submit, the current posted comment will be showed in here -->
    <div class="comment_date_added">Monday 31 January 2011, 1:23 pm</div>
    <div class="comment_content">ccc</div>
    <div class="comment_date_added">Monday 31 January 2011, 1:22 pm</div>
    <div class="comment_content">bbb</div>
    </div>
    </div><!--second  div.articlewarp end-->
    HTML:
     
    cj333, Jan 31, 2011 IP
  2. cj333

    cj333 Peon

    Messages:
    14
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I am sorry, I can not open in opera 10, so I think the link is broken. I posted this question again.
    Dear Admin, please delete my another question, thanks.
    [​IMG]
     
    cj333, Jan 31, 2011 IP