<?PHP $results = mysql_query("SELECT * FROM messages, comments WHERE messages.user_on='$user2' AND comments.msg_id_fk = messages.msg_id ORDER BY messages.msg_id, comments.com_id DESC") or die(mysql_error()); ?>

Recommended Answers

All 4 Replies

Member Avatar for rajarajan2017

Execute the query in your phpadmin seperately and identify the error first. If samething happen there, then correct it by checking your records properly

Do you get any kind of error? Maybe the condition comments.msg_id_fk = messages.msg_id actually returns one row ... check your data.

another possible problem: are you looping through the records?

Hey,
List your code : How are you displaying your $results values.

I don't get any errors and yes I'm loop though my records

<?PHP 
include_once "scripts/connect_to_mysql.php";
include("db.php");//Connect to Database
include("tolink.php");


$results = mysql_query("SELECT * FROM messages, comments WHERE messages.user_on='$user2' AND comments.msg_id_fk = messages.msg_id ORDER BY messages.msg_id, comments.com_id DESC") or die(mysql_error());
$messagedump='';
while ($row = mysql_fetch_assoc($results)) {
 
 
$idt=$row['msg_id'];//Message id
$msg=$row['message'];//The Message
$useron=$row['username'];//This is the user where the message is posted on
$date=$row['date'];//Message date
//$msg=toLink($msg);
$id=$row['com_id'];//Comment id
$comment=$row['comment'];//The Comment
$comment=wordwrap($comment, 38, "<br />", true);//Line break every 38 characters long
$date2=$row['_date'];//Comment date
$usernameqw=$row['_username'];//User who posted the comment
 
 
  //Get the picture for the user where the message was posted
	$check_pic = "members/$useron/image01.png";
	$default_pic = "members/0/image01.jpg";
	if (file_exists($check_pic)) {
    $user_picpost = "<img src=\"$check_pic\" width=\"50px\"  alt=\"$useron\" title=\"$useron\"  />"; 
	} else {
	$user_picpost = "<img src=\"$default_pic\" width=\"50px\" alt=\"$useron\" title=\"$useron\"  />"; 
	}
	//Get the session users picture
	$check_pic = "members/$username/image01.png";
	$default_pic = "members/0/image01.jpg";
	if (file_exists($check_pic)) {
    $user_pic2post = "<img src=\"$check_pic\" width=\"32px\"  alt=\"$username\" title=\"$username\" />"; 
	} else {
	$user_pic2post = "<img src=\"$default_pic\" width=\"32px\" alt=\"$username\" title=\"$username\" />"; 
	}
	//Get the user who posted the comments image 
	$check_pic = "members/$usernameqw/image01.png";
	$default_pic = "members/0/image01.jpg";
	if (file_exists($check_pic)) {
    $user_pic2post3 = "<img src=\"$check_pic\" width=\"32px\"  alt=\"$usernameqw\" title=\"$usernameqw\" />"; 
	} else {
	$user_pic2post3 = "<img src=\"$default_pic\" width=\"32px\" alt=\"$usernameqw\" title=\"$usernameqw\" />"; 
	}

 
if ($messagedump!=$msg) {
	$messagedump=$msg;
 
 
 
$message_post .='
<li class="bar'.$idt.'"  onMouseover=\'document.getElementById("del'.$idt.'").style.display="";\' onMouseout=\'document.getElementById("del'.$idt.'").style.display="none";\'>
<div align="left" class="post_box"> 
<div class="left_post">'.$user_picpost.'</div>
<div class="right_postd"><span class="font3">'.$useron.'</span>&nbsp;<span class="font2">'.$msg.'</span><br /><div class="feed_link">'.$date.''. (($username !== "") ? "&nbsp;-&nbsp;" : "") .'<a href="javascript: void(0)" class="comment" id="'.$id.'">'. (($username !== "") ? "Comment" : "") .'</a></div></div>
<div class="right_post"><span class="delete_button" id="del'.$idt.'" style="display:none;"><a href="javascript: void(0)" id="'.$id.'" class="delete_update">'. (($useron == $username || $user2 == $username) ? "<div class=\"hover_delete\"></div>" : "") .'</a></span></div>
<div class="clearer"></div>
</div>


<div id="expand_box" >
<div id="expand_url"></div>
</div>

<div class="lft">
<div id="fullbox" class="fullbox'.$id.'">
<div id="commentload'.$id.'">
</div>
<div class="comment_box" id="c'.$id.'">
<div class="left_com">'.$user_pic2post.'</div>
<div class="right_com">
<form method="post" action="" name="'.$id.'">
<textarea class="text_area" name="comment_value" id="textarea'.$id.'" onKeyDown="limitText(this,100);" 
onKeyUp="limitText(this,100);">
Write a comment...</textarea><br />
<input type="submit" value="Comment" class="comment_submit" id="'.$id.'"/>
</form>
</div>
<div class="cl"></div>
</div>
</div>
</div>
';	
}

$message_post .='
<div class="lft">
<div class="comment_load_box">
<div class="left_post">'.$user_pic2post3.'</div>
<div class="right_post"><span class="font4">'.$usernameqw.'</span>&nbsp;<span class="font5">'.$comment.'</span><br />
<span class="font11">'.$date2.''. (($username == $user2) ? "&nbsp;-&nbsp;" : "") .'</span><a href="javascript: void(0)" id="'.$id2.'" class="cdelete_update">'. (($username == $user2) ? "<span class=\"font111\">Delete</span>" : "") .'</a></div>
<div class="cl"></div>
</div>
</div>
</li>
';
}




?>
<ol class="timeline2">
<? echo"$message_post";//Display the message with all the comments for it?>
</ol>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.