Jump to content

having trouble with a java and php script


co.ador

Recommended Posts

I want to id each comment so that where any member response on a comment, the INSERT and the SELECT knows where to display the responses, to what comment the responses belong to. t. it is like creating an id for each comment so the SELECT display each responses below in its messages. but i don't know if it is an html, php or javascript issue to handle below there are two forms, the parent form and the responses form below each comment form, I want the responses to display below each comment to what it belongs too. I have some tables structure problems and some html issues. the javascript is working for the parent comment it is working perfectly but for the second form the responses form it is not displaying below the comments.

<?php 
$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("'", "&#38;#39;", $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("'", "&#38;#39;", $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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.