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 phython如何实现以下功能?查找同一用户名的消费金额合并—
  • ¥15 孟德尔随机化怎样画共定位分析图
  • ¥18 模拟电路问题解答有偿速度
  • ¥15 CST仿真别人的模型结果仿真结果S参数完全不对
  • ¥15 误删注册表文件致win10无法开启
  • ¥15 请问在阿里云服务器中怎么利用数据库制作网站
  • ¥60 ESP32怎么烧录自启动程序
  • ¥50 html2canvas超出滚动条不显示
  • ¥15 java业务性能问题求解(sql,业务设计相关)
  • ¥15 52810 尾椎c三个a 写蓝牙地址