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>";
}
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).