dongxing5525 2013-02-14 17:16
浏览 45
已采纳

我在while循环中显示数组的结果时遇到问题

I am new to php and am having a problem echoing a result from the database. Everything above the div tags executes fine and displays in my table properly. But the problem I am having is within the div tags.

  1. while($row = mysql_fetch_array($result))
  2. {
  3. if ($row['status']==0){
  4. $row['status']="Inactive";
  5. $lablestatus="label";
  6. }
  7. elseif ($row['status']==1){
  8. $row['status']="Pending";
  9. $lablestatus="label label-warning";
  10. }
  11. elseif ($row['status']==2){
  12. $row['status']="Banned";
  13. $lablestatus="label label-important";
  14. }
  15. elseif ($row['status']==3){
  16. $row['status']="Active";
  17. $lablestatus="label label-success";
  18. }
  19. echo "<tr>
  20. <td>{$row['id']}</td>
  21. <td class='center'>{$row['username']}</td>
  22. <td class='center'>17</td>
  23. <td class='center'>36</td>
  24. <td class='center'>17</td>
  25. <td class='center'>$458.66</td>
  26. <td class='center'>Yes</td>
  27. <td class='center'>{$row['register_date']}</td>
  28. <td class='center'>2013-02-13 24:06:13</td>
  29. <td class='center'>Yes</td>
  30. <td class='center'><span class='$lablestatus'>{$row['status']}</span></td>
  31. <td class='center'>
  32. <a class='btn btn-success' href='view_user.php?id={$row['id']}'>
  33. <i class='icon-zoom-in icon-white'></i>View</a>
  34. <a class='btn btn-info' href='edit_user.php?id={$row['id']}'>
  35. <i class='icon-edit icon-white'></i>Edit</a>
  36. <a class='btn btn-danger btn-setting'>
  37. <i class='icon-trash icon-white'></i>Delete</a>
  38. </td>
  39. </tr>

Here is where the problem occurs. When I click delete for a certain user, a popup is displayed. It asks "Are you sure you want to delete the user exampleuser?" The same username is displayed for each user in my table. So if i click delete for exampleuser2, It will ask if I want to delete exampleuser. Any idea how to fix this?

  1. <div class='modal hide fade' id='myModal'>
  2. <div class='modal-header'>
  3. <button type='button' class='close' data-dismiss='modal'>×</button>
  4. <h3>Delete member</h3>
  5. </div>
  6. <div class='modal-body'>
  7. <p>Are you sure you want to delete the user {$row['username']}?</p>
  8. </div>
  9. <div class='modal-footer'>
  10. <a href='#' class='btn' data-dismiss='modal'>No</a>
  11. <a href='delete_user.php?id={$row['id']}' class='btn btn-primary'>Yes</a>
  12. </div>
  13. </div>";
  14. }

展开全部

  • 写回答

1条回答 默认 最新

  • dongniechi7825 2013-02-14 22:33
    关注

    AS your pop up code is inisde while loop

    1. <div class='modal hide fade' id='myModal'>
    2. <div class='modal-header'>
    3. <button type='button' class='close' data-dismiss='modal'>×</button>
    4. <h3>Delete member</h3>
    5. </div>
    6. <div class='modal-body'>
    7. <p>Are you sure you want to delete the user {$row['username']}?</p>
    8. </div>
    9. <div class='modal-footer'>
    10. <a href='#' class='btn' data-dismiss='modal'>No</a>
    11. <a href='delete_user.php?id={$row['id']}' class='btn btn-primary'>Yes</a>
    12. </div>
    13. </div>";

    Your div id is not unique id='myModal', I guess all the time it takes for the first/last div. There can not be multiple id a page

    Make it dynamic <div class='modal hide fade' id='myModal_{$row['id']}'> some thing like this and change your js pop up code and try (I guess your are specifying this id while clicking the delete link there also make it dynamic to match proper pop ups).

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部