Hello,
In my php code, I am retrieving entries from a table in the database and displaying them on the webpage using a while loop.
The while loop creates a button that opens a dialog form when clicked and it displays some values from the database.
With my code below, the dialog form only always display values the topmost record no matter which button is clicked. In other words, the subj, cont, stats, pid attributes of the button do not get updated even though the value of $row{'message_subject'} inside the button tag is showing me the correct value for each loop.
<button class='btn-msg' pid=".
$row{'patient_id'}." subj='".
$row{'message_subject'}."' cont='".
$row{'message_content'}."' stats='".
$row{'status'}."'>".
$row{'message_subject'}.
"</button></td>";
Can someone tell me what is wrong and how I can fix this?
javascript code ...
$(function() {
$( ".btn-msg" ).click(function() {
var pid = $('.btn-msg').attr('pid');
var subj = $('.btn-msg').attr('subj');
var cont = $('.btn-msg').attr('cont');
var stat = $('.tbn-msg').attr('stats');
$("#msg-subj").html(""+subj);
$("#msg-content").val(""+cont);
$( "#msg-dialog" ).dialog({
autoOpen:false,
hide: "puff",
show: "slide",
buttons: {
Send: function() {
$( this ).dialog( "close" );
},
Close: function() {
$( this ).dialog( "close" );
}
}
});
$( "#msg-dialog" ).dialog( "open" );
});
});
php ... code
while ($row = mysql_fetch_assoc($query_exec)) {
echo "<tr>";
echo "<td>".$patient." </td>";
echo "<td>".$row{'date'}."</td><td>".$row{'time'}."</td>";
if($row{'message_subject'}!= null && $row{'message_content'}!=null) {
echo "<td>
<button class='btn-msg' pid=".
$row{'patient_id'}." subj='".
$row{'message_subject'}."' cont='".
$row{'message_content'}."' stats='".
$row{'status'}."'>".
$row{'message_subject'}.
"</button></td>";
} else {
echo "<td>". $row{'voice_file'}."</td>";
}
echo "<td>".$row{'status'}."</td>";
echo "</tr>";
}
Dialog Form:
<div id="msg-dialog">
<h3 id="msg-subj"></h3>
<select id="msg-status">
<option value="unread">Unread</option>
<option value="read">Read</option>
<option value="respond">Responded</option>
<option value="pending">Pending</option>
</select>
<textarea id="msg-content"></textarea>
<textarea id="msg-response"></textarea>
</div>