doddsey_65 Posted March 1, 2011 Share Posted March 1, 2011 im setting up a php and jQuery pm system and have run into a problem. When a user clicks on a message in the left column the right column is supposed to be populated with the message contents, however the content stays the same whichever message is clicked. <?php $query = $link->query("SELECT * FROM ".TBL_PREFIX."messages WHERE m_sent_to = '$user_name'") or die(print_link_error()); $row = $query->fetchAll(); foreach($row as $key => $value) { $_message_list .= '<dl class="message_row" id="row-'.$row[$key]['m_mid'].'">'; $_message_list .= '<dd class="message_author">'.profile_link($row[$key]['m_author']).'</dd>'; $_message_list .= '<dd class="message_date">'.asf_date($row[$key]['m_date_sent'], 'short').'</dd>'; $_message_list .= '<dd class="message_checkbox"><input type="checkbox" id="checkbox-'.$row[$key]['m_mid'].'" /></dd>'; $_message_list .= '<dd class="message_subject">'.$row[$key]['m_subject'].'</dd>'; $_message_list .= '</dl>'; $template->message_content = $row[$key]['m_content']; } ?> and the jQuery <script type="text/javascript"> $j = jQuery.noConflict(); $j(document).ready(function(){ $j('dl.message_row').click(function(){ $j('li.message').html('<?php echo $this->message_content; ?>'); }); }); </script> The content display is always the content of the last message. Quote Link to comment https://forums.phpfreaks.com/topic/229271-private-messaging-system/ Share on other sites More sharing options...
isedeasy Posted March 1, 2011 Share Posted March 1, 2011 That's because you are echoing out php into the jquery .html() method You need to either have the contents for all the posts hidden on the page or use AJAX to pull in the messages when required. untested example $_message_list .= '<dd class="message_content">'.profile_link($row[$key]['m_content']).'</dd>'; <script type="text/javascript"> $j = jQuery.noConflict(); $j(document).ready(function(){ $j('dl.message_row').click(function(){ $j('li.message').html($j(this).siblings('.message_content')); }); }); </script> That each method has its advantages/disadvantages AJAX method + only getting the content you want - every time the user clicks a message to are doing a http request and a database query Hide/Show method + only one database query - you are getting every comment on page load even if the user will not see them Hope this helps Quote Link to comment https://forums.phpfreaks.com/topic/229271-private-messaging-system/#findComment-1181400 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.