我只是想问一个更好的想法。场景是这样的: 1.在可点击的表格行上显示消息。如果消息已被读取,则无法单击该行 2.一旦点击它将打开一个用于回复消息的弹出窗口。当窗口关闭时,页面应该刷新。
问题是我只能获取最后一行数据。似乎会话变量被覆盖。
<?php
//Display Messages Starts Here
$msg = "SELECT * FROM messages WHERE sid=". $_SESSION['SESS_SERVICE_ID'] ."";
$resulta = mysql_query($msg)or die(mysql_error());
while($row = mysql_fetch_array($resulta))
{
if($row['status']=='deleted'){
echo "<tr bgcolor=#AAAAAA>";
echo "<td>" . date("Y-m-d",strtotime($row['stamp'])) . "</td>";
echo "<td>" . $row['msisdn'] . "</td>";
echo "<td width=100%>" . $row['data'] . "</td>";
echo "</tr>";
}
else{
// id like to use this to a popup form for reply
echo "<tr onmouseover='ChangeColor(this, true);'
onmouseout='ChangeColor(this, false);'
onclick=\"DoNav();\">";
echo "<td>" . date("Y-m-d",strtotime($row['stamp'])) . "</td>";
echo "<td>" . $row['msisdn'] . "</td>";
$_SESSION['SESS_MSG_ID'] = $row['id'];
$_SESSION['SESS_MSG_DATA'] = $row['data'];
echo "<td width=100%>" . $row['data'] . "</td>";
$_SESSION['SESS_MSG_NUM'] = $row['msisdn'];
echo "</tr>";
}
}
?>
答案 0 :(得分:0)
您正在设置$_SESSION
变量,并且每次都会覆盖此变量。
您最好将其存储在数组中,例如:
$_SESSION[$row['id']]['SESS_MSG_DATA'] = $row['data'];
然后将onClick更改为:
onclick=\"DoNav(".$row['id'].");
当然还有DoNav功能:
function DoNav(row_id){
window.open( "reply.php?id="+row_id, "myWindow", "status = 1, height = 300, width = 555, resizable = 0" );
}
然后在reply.php中,获取带有$_GET['id'];
的ID并从会话中获取数据,如下所示:
$_SESSION[$_GET['id']]['SESS_MSG_DATA'];
除了SESS_MSG_DATA,你可以将它们全部存储在这个数组中:
$_SESSION[$row['id']][ANY VARIABLE HERE]