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 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看