dongxing5525 2013-02-15 01: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.

while($row = mysql_fetch_array($result))
    {
    if ($row['status']==0){
    $row['status']="Inactive";
    $lablestatus="label";
    }
    elseif ($row['status']==1){
    $row['status']="Pending";
    $lablestatus="label label-warning";
    }
    elseif ($row['status']==2){
    $row['status']="Banned";
    $lablestatus="label label-important";
    }
    elseif ($row['status']==3){
    $row['status']="Active";
    $lablestatus="label label-success";
    }                
           echo "<tr>
                 <td>{$row['id']}</td>
                 <td class='center'>{$row['username']}</td>
                 <td class='center'>17</td>
                 <td class='center'>36</td>
                 <td class='center'>17</td>
                 <td class='center'>$458.66</td>
                 <td class='center'>Yes</td>
                 <td class='center'>{$row['register_date']}</td>
                 <td class='center'>2013-02-13 24:06:13</td>
                 <td class='center'>Yes</td>
                 <td class='center'><span class='$lablestatus'>{$row['status']}</span></td>
                 <td class='center'>
                    <a class='btn btn-success' href='view_user.php?id={$row['id']}'>
                    <i class='icon-zoom-in icon-white'></i>View</a>
                    <a class='btn btn-info' href='edit_user.php?id={$row['id']}'>
                    <i class='icon-edit icon-white'></i>Edit</a>
                    <a class='btn btn-danger btn-setting'>
                    <i class='icon-trash icon-white'></i>Delete</a>
                 </td>
                 </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?

<div class='modal hide fade' id='myModal'>
                 <div class='modal-header'>
                 <button type='button' class='close' data-dismiss='modal'>×</button>
         <h3>Delete member</h3>
                 </div>
                 <div class='modal-body'>
         <p>Are you sure you want to delete the user {$row['username']}?</p>
                 </div>
         <div class='modal-footer'>
                 <a href='#' class='btn' data-dismiss='modal'>No</a>
                 <a href='delete_user.php?id={$row['id']}' class='btn btn-primary'>Yes</a>
                 </div>
                 </div>";
            }
  • 写回答

1条回答 默认 最新

  • dongniechi7825 2013-02-15 06:33
    关注

    AS your pop up code is inisde while loop

    <div class='modal hide fade' id='myModal'>
                     <div class='modal-header'>
                     <button type='button' class='close' data-dismiss='modal'>×</button>
             <h3>Delete member</h3>
                     </div>
                     <div class='modal-body'>
             <p>Are you sure you want to delete the user {$row['username']}?</p>
                     </div>
             <div class='modal-footer'>
                     <a href='#' class='btn' data-dismiss='modal'>No</a>
                     <a href='delete_user.php?id={$row['id']}' class='btn btn-primary'>Yes</a>
                     </div>
                     </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).

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

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog