PHP Message system with JQuery Effects some logic help please
<p>I've for a while on my website had a simple PHP Message system, worked fine, stores the data into MySQL and each message has a unique ID. Well out of no where I decided to add in JQuery effects for when you send and delete messages. I can get it to work if its just one message, but when there multiple messages, the JQuery can't figure out where to pull the info from because the data needs unique ways of identifying what's what. Here's what I've done to try and fix it. It's probably completely rediculous and you guys are going to laugh at me, but I've been working on this for like 6 hours now and can't get it to work. </p>

<pre><code>    $get_new_messages = mysql_query("SELECT * FROM messages WHERE to_user='$id' AND message_read = '0' ORDER BY message_id DESC");
    while($messages = mysql_fetch_array($get_new_messages))
    {
    $message_id = $messages['message_id'];
    $from = $messages['from_user'];
    $from_username = $messages['from_username'];
    $pic_from = $messages['defaultpic_from'];
    $title = $messages['message_title'];
    $content = $messages['message_contents'];


    $new_messages .="&lt;!--TITLE--&gt;
    &lt;div id=\"div_$message_id\"&gt;&lt;!-- ACCORDION ELEMNT BEGINING--&gt;
    &lt;script type=\"text/javascript\"&gt;
    $(document).ready(function(){
        $(\"#reply_message_$message_id\").click(function() { 
        var to_user_$message_id = encodeURIComponent($('#to_user_$message_id').val()); 
        var from_user_$message_id = encodeURIComponent($('#from_user_$message_id').val())); 
        var defaultpic_from_$message_id  = encodeURIComponent($('#defaultpic_from_$message_id').val()); 
        var defaultpic_to_$message_id = encodeURIComponent($('#defaultpic_to_$message_id').val()); 
        var your_username_$message_id = encodeURIComponent($('#your_username_$message_id').val()); 
        var message_title_$message_id = encodeURIComponent($('#message_title_$message_id').val()); 
        var message_contents_$message_id = encodeURIComponent($('#message_contents_$message_id').val()); 
        var location2 = '#div_$message_id';
        var location3 = '#reply_success';
            $.ajax({ 
                type: \"POST\", 
                url: \"send_note.php\", 
                data: {to_user:to_user_$message_id, from_user:from_user_$message_id, defaultpic_from: defaultpic_from_$message_id, defaultpic_to:defaultpic_to_$message_id, your_username:your_username_$message_id, message_title:message_title_$message_id, message_contents:message_contents_$message_id}, 
                success: 
                $(location2).fadeOut();
                $(location3).fadeIn();
            }); 
        return false; 
        }); 

        $(\"#delete_message_button_$message_id\").click(function() {
        var  deleteId    = $('#deleteID_$message_id').val();
        var  location = '#div_$message_id';
        var location4 = '#delete_message_success';
            $.ajax({
                type: \"POST\",
                url: \"delete.php\",
                data: \"deleteId=\"+ deleteId,
                success: 
                $(location).fadeOut();
                $(location4).fadeIn();

            });
        return false;
        });

    });
    &lt;/script&gt;
    &lt;div class=\"title\"&gt;
    $title
    &lt;/div&gt;
    &lt;!--TITLE END--&gt;


    &lt;div class=\"inside\"&gt;&lt;!-- THIS DIV CONTAINS EVERYTHING INSIDE THE SELECTED ACCORDION ELEMENT--&gt;

&lt;form name=\"send_note_$message_id\" id=\"$message_id\" class=\"form_right\"&gt;
    &lt;input type=\"hidden\" name=\"message_id_$message_id\" id=\"message_id_$message_id\" value=\"$message_id\"&gt;
    &lt;input type=\"hidden\" name=\"to_user_$message_id\" id=\"to_user_$message_id\" value=\"$from\"&gt;
    &lt;input type=\"hidden\" name=\"from_user_$message_id\" id=\"from_user_$message_id\" value=\"$id\"&gt;
    &lt;input type=\"hidden\" name=\"defaultpic_from_$message_id\" id=\"defaultpic_from_$message_id\" value=\"$default_pic_session\"&gt;
    &lt;input type=\"hidden\" name=\"defaultpic_to_$message_id\" id=\"defaultpic_to_$message_id\" value=\"$pic_from\"&gt;
    &lt;input type=\"hidden\" name=\"your_username_$message_id\" id=\"your_username_$message_id\" value=\"$username_session\"&gt;
    &lt;input type=\"hidden\" name=\"message_title_$message_id\" id=\"message_title_$message_id\" value=\"$username_session Replied to your Note!\"&gt;
    &lt;img class=\"pic_from_body_right\" src=\"$default_pic_session\"&gt;
    &lt;textarea class=\"message_text\" name=\"message_contents_$message_id\" 

    id=\"message_contents_$message_id\" placeholder=\"Reply to $from_username here...\"&gt;&lt;/textarea&gt;
        &lt;br /&gt;

        &lt;p class=\"reply_delete\"&gt;
        &lt;input type=\"hidden\" id=\"deleteID_$message_id\" value=\"$message_id\"&gt;
        &lt;button id=\"delete_message_button_$message_id\"&gt;Delete&lt;/button&gt;
        &lt;button id=\"reply_message_$message_id\"&gt;Reply&lt;/button&gt;
        &lt;/p&gt; 
        &lt;/form&gt; 
        &lt;/div&gt;
        &lt;/div&gt;";    
    }
</code></pre>

<p>It grabs the message and echos it out correctly, all of that works fine, just the JQuery delete and reply don't work. Can't figure it out. Is there maybe a way to have the JQuery in a seprate file but the JQuery will know the correct message to delete.</p>

<p>I am not a very good programmer, self taught, so I apologize if my description stinks, i don't always know the proper terms for things, but I try. 
Thanks so much for taking the time to read this.
-Mike</p>
