duankuan5319 2014-01-27 08:22
浏览 29
已采纳

Javascript弹出窗口仅显示PHP查询中的最后一个结果

I have the following block of code and I'm not sure how to do what I'm wanting to do.

In essence I'm wanting the javascript popup to display that row's value, but (obviously) it's only showing the final row of data as the popup isn't set for each row but rather calls the variable when clicked.

Any help would be appreciated!

<?php
$result = mysql_query("SELECT hr_overtime.overtime_id, hr_user.name, hr_overtime.overtime_date, hr_overtime.overtime_type, hr_overtime.overtime_from, hr_overtime.overtime_to, hr_overtime.overtime_amount, hr_overtime.details
FROM hr_overtime 
inner join hr_user
on hr_user.user_id = hr_overtime.user_id
where hr_overtime.overtime_status = 'Pending' order by hr_overtime.overtime_date ASC");
echo "
<table border='0'>
<tr>
<th class='tablecell_header'>Consultant</th>
<th class='tablecell_header'>Date</th>
<th class='tablecell_header'>Type</th>
<th class='tablecell_header'>From</th>
<th class='tablecell_header'>To</th>
<th class='tablecell_header'>Amount</th>
<th> </th>
<th> </th>
<th> </th>
</tr>";
while($row = mysql_fetch_array($result))
  {
  $work = $row['details'];
  echo "<tr>";
    echo "<td class='tablecell'>" . $row['name'] . "</td>";
    echo "<td class='tablecell'>" . $row['overtime_date'] . "</td>";
    echo "<td class='tablecell'>" . $row['overtime_type'] . "</td>";
    echo "<td class='tablecell'>" . $row['overtime_from'] . "</td>";
    echo "<td class='tablecell'>" . $row['overtime_to'] . "</td>";
    echo "<td class='tablecell'>" . $row['overtime_amount'] . "</td>";?>
    <td class='tablecell'> <button onclick="myFunction()">Show work</button>         </td><script>
function myFunction()
{
alert("<?php echo $work;?>");
}
</script>
        <?php
    echo "<td valign='middle'><form action='manager_overtime_approve.php'     method='post'>
<input name='approve_id' type='hidden' value='" . $row['overtime_id'] . "' />
<input type='submit' value='APPROVE' id='edit' />
</form></td>";
    echo "<td valign='middle'><form action='manager_overtime_reject.php' method='post'>
<input name='cancel_id' type='hidden' value='" . $row['overtime_id'] . "' />
<input type='submit' value='REJECT' id='edit' />
</form></td>";
 echo "</tr>";
  } 
    echo "</table>";
?>
  • 写回答

5条回答 默认 最新

  • douyan6548 2014-01-27 08:29
    关注

    There is no need for a separate function which you are using incorrectly. You can simply use an inline alert for this:

    <td class='tablecell'> <button onclick="alert('<?php echo $work;?>');">Show work</button>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制
  • ¥20 usb设备兼容性问题
  • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊
  • ¥15 安装svn网络有问题怎么办
  • ¥15 vue2登录调用后端接口如何实现