Is this even possible?

I was trying to figure out the best way to do this
I have a mysql table (members) which has a display record which is boolean data type (0 is no, 1 is yes),
I created a delete button for each member

Each row is generated using


    echo "<tr>";
    echo "<td><img src='".$row['image']."'></td>\
";
    echo "<td>".$row['name']."</td>\
";
    echo "<td>".$row['email']."</td>\
";
    echo "<td>".date("m/d/Y",strtotime($row['created']));
    echo "<span class='pull-right'><a href='edit_user.php?id=".$row['id']."' class='btn btn-warning btn-xs glyphicon glyphicon-pencil' role='button'></a>\
";
	echo "&nbsp;&nbsp;&nbsp;";
// Button trigger modal 
	echo "<a href='#' role='button' class='btn btn-danger btn-xs glyphicon glyphicon-trash' data-toggle='modal' data-target='#myModal'>";
  	echo "</a></td>\
";
    echo "</tr>\
";

When i click the delete icon, a modal pops up asking me to confirm

Im trying to use PHP to put values (name) into the modal so I can be positive as to who I am deleting.
How do I carry those variables into the modal?

This is a CSS modal box setup. Rather than a Javascript confirm type popup, any data can be put in the modal. In this sample page I put the name and a form to POST delete with the user id. Not thrilled about putting the modal within a new table row but it is what it is. You can configure as you wish.

<?php 
//Test Post
if(isset($_POST['delete'])):
	echo "<pre>";
	print_r($_POST);
	echo "</pre>";
endif;
 ?>
<html>
<head>
<title>modal box</title>
<style type="text/css">
.modalDialog {
	position: fixed;
	font-family: Arial, Helvetica, sans-serif;
	top: 0;
	right: 0;
	bottom: 0;
	left: 0;
	background: rgba(0,0,0,0.8);
	z-index: 99999;
	opacity:0;
	-webkit-transition: opacity 400ms ease-in;
	-moz-transition: opacity 400ms ease-in;
	transition: opacity 400ms ease-in;
	pointer-events: none;
}
.modalDialog:target {
	opacity:1;
	pointer-events: auto;
}

.modalDialog > div {
	width: 400px;
	position: relative;
	margin: 10% auto;
	padding: 5px 20px 13px 20px;
	border-radius: 10px;
	background: #fff;
	background: -moz-linear-gradient(#fff, #999);
	background: -webkit-linear-gradient(#fff, #999);
	background: -o-linear-gradient(#fff, #999);
}	
.close {
	background: #606061;
	color: #FFFFFF;
	line-height: 25px;
	position: absolute;
	right: -12px;
	text-align: center;
	top: -10px;
	width: 24px;
	text-decoration: none;
	font-weight: bold;
	-webkit-border-radius: 12px;
	-moz-border-radius: 12px;
	border-radius: 12px;
	-moz-box-shadow: 1px 1px 3px #000;
	-webkit-box-shadow: 1px 1px 3px #000;
	box-shadow: 1px 1px 3px #000;
}

.close:hover { background: #00d9ff; }
</style>
<body>
<?php
//Page name
$page = "?";
//Sample data to replace query results for test
$data = array(
	0 => array(
		'id' => "22",
		'image' => "image1.jpg",
		'name' => "John Doe",
		'email' => "John@ggmail.com",
		'created' => "2014-06-22"
		),
	1 => array(
		'id' => "26",
		'image' => "image2.jpg",
		'name' => "Peggy Sue",
		'email' => "Peggy@ggmail.com",
		'created' => "2014-06-22"
		)
);
echo "<table>";
//sample loop
foreach($data as $k => $row):
	echo "<tr>";
		echo "<td><img src='".$row['image']."'></td>\
";
		echo "<td>".$row['name']."</td>\
";
		echo "<td>".$row['email']."</td>\
";
		echo "<td>".date("m/d/Y",strtotime($row['created']))."</td>\
";
		echo "<td><a href='#openModal".$k."'>Delete</a></td>\
";
	echo "</tr>\
";	
	//Build Modal box
	echo '<tr>
	<td>
	<div id="openModal'.$k.'" class="modalDialog">
	<div>
		<a href="#close" title="Close" class="close">X</a>
		<h2>Delete Confirmation</h2>
		<p>Are you sure you wish to delete '.$row['name'].' from the records?</p>
		
		<form action="'.$page.'" method="post">
		<input type="hidden" name="user_id" value="'.$row['id'].'" />
		<input type="submit" name="delete" value="Delete" />
		</form>
		
	</div>
</div>
</td>
</tr>'."\\r";
endforeach;
echo "</table>";
?>

If you built a data array with your query result instead of looping it to build your table, you could loop through this data array for the table and a separate loop for the modal div loop.

thanks, thats exactly what I was trying to do…
thankss

I do think you should build that data array so you can build the modal div in a separate loop. I believe it could be built something like this.

$data = array();
while($row = $query->fetch(PDO::FETCH_ASSOC)){
	$data[$row['id']]['id']      = $row['id'];
	$data[$row['id']]['image']   = $row['image'];
	$data[$row['id']]['name']    = $row['name'];
	$data[$row['id']]['email']   = $row['email'];
	$data[$row['id']]['created'] = $row['created'];
}