我正在为一个大学项目创建一个糖尿病管理系统。该系统的功能之一是患者能够发送最新的葡萄糖读数,护士能够登录并评论这些读数。
我已经能够对患者功能进行编码,但是我希望在评论列中添加一个评论按钮,单击该按钮时,会弹出一个弹出窗口或文本框,供护士对该特定记录进行评论。如果尚未输入注释,则应出现一个空框,但是如果以前输入了注释,则应将其显示在要更新的框中并发送回mysql数据库。我想问一下是否有人可以给我一种方法来包含此注释框和要在框中显示的现有值的代码,如果没有现有注释,则可以输入新注释并将其存储在数据库中。
下面是我的php代码。
<?php//run query
$result = mysql_query($GetReadings);
?>
<table>
<tr>
<th>Date</th>
<th>Time</th>
<th>Glucose Level</th>
<th>SBP</th>
<th>DBP</th>
<th>Comments</th>
</tr>
<?php
//display results
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
?>
<tr>
<td><?php echo $row["Date"]; ?> </td>
<td><?php echo $row["Time"]; ?> </td>
<td><?php echo $row["GlucoseLevel"]; ?> </td>
<td><?php echo $row["SBP"]; ?> </td>
<td><?php echo $row["DBP"]; ?> </td>
<td><?php echo $row["Comments"];
<?php
//if statement to add comment link if user is a nurse
if ($_SESSION['User_level'] == 2)
{
//code for comments
}
?> </td>
</tr>
<?php
//end of while loop
}
?>
希望我没有错过任何关键信息。
使用 javascript 函数:
window.open(URL, windowName[, windowFeatures])
其中,URL - desired URL to display a page containing Textbox
,使用所需的任何窗口名称。
回显<a>
或button
与点击事件,例如:
<a href="#" onlick="window.open('somePage.php?id=<? echo $row['id']?>', 'Window Name')">Add Comment</a>
编辑
最基本的实现方法是回显包含过去注释的<div></div>
、新注释文本框和发送/取消按钮。诀窍是设置该div 的 display:none
样式属性。您以下代码是一个准则:如果用户具有正确的用户级别,则回显以下代码。
<a href="#" onclick="showComment('<?php echo $row['id']?>')">Show Comments</a>
<div id="comment-<?php echo $row['id']?>" style="display:none">
//display previous comments
<form method="post" action="addComment.php?id=<?php echo $row['id']?>">
<textarea name="comment"></textarea>
<input type="submit" value="Add Comment" /><input type="button" onclick="hideComment('<?php echo $row['id']?>')">
</form>
</div>
<script type="text/javascript">
function hideComment(id) {
document.getElementById('comment-' + id).style.display = 'none';
}
function showComment(id) {
document.getElementById('comment-' + id).style.display = 'block';
}
</script>