Jump to content

private messaging system


doddsey_65

Recommended Posts

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.

Link to comment
Share on other sites

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

 

 

 

 

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.