简体   繁体   English

我在while循环中显示数组结果有问题

[英]I am having problems displaying a result from an array in a while loop

I am new to php and am having a problem echoing a result from the database. 我是php新手,在从数据库中回显结果时遇到问题。 Everything above the div tags executes fine and displays in my table properly. div标签上方的所有内容都能正常运行,并正确显示在我的表格中。 But the problem I am having is within the div tags. 但是我遇到的问题是在div标签内。

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?" 它询问“您确定要删除用户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. 因此,如果我单击exampleuser2的删除,它将询问我是否要删除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>";
            }

AS your pop up code is inisde while loop 因为您的弹出代码在循环时是inisde

<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. 您的div ID不是唯一的id='myModal' ,我想所有的时间都是第一个/最后一个div。 There can not be multiple id a page 一个页面不能有多个ID

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). 使它成为动态<div class='modal hide fade' id='myModal_{$row['id']}'>事情,并更改您的js弹出代码,然后尝试尝试(我想您是在单击时指定了此id删除链接也会使其动态地匹配相应的弹出窗口)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM