I am trying to display hilios countdown jquery plugin for each member but same countdown is displaying for all member. image is showing that the countdown for all memebers is same. pLease help .i am echoeing expiry for all members from database of column with name "expiry" and "expiry" is not echoing hilios countdown for all members
<?php
$sql = "SELECT d.*, c.* from details as d, customer as c where d.customerId = c.id AND c.cmpId = '$idCompany'";
/*$sql = "SELECT * from customer where cmpId = '$idCompany' ";*/
$result = mysqli_query($conn, $sql);
while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
?>
<tbody>
<tr>
<td>
<?php echo $row['id'] ?>
</td>
<td>
<?php echo '<img src="images/'.$row['image'].'"; width="100px"; hieght="100px">' ?>
<?php echo $row['fname']." ".$row['lname']?>
<span class="user-subhead">Member</span>
</td>
<td>
<?php echo $row['time'] ?>
</td>
<td class="text-center countdown">
<!-- Countdown (please check this countdown where the expiry for each member has to echo but same expiry is echoing for all members)-->
<span class="label label-default getting-started"></span>
<script type="text/javascript">
$(".getting-started").each(function(){
$('.getting-started').countdown('<?php echo $row["expiry"] ?> ' , function(time) {
$(this).html(time.strftime('%w wk %d d %H h %M m %S s'));
});
})
//})
</script>
</td>
<td>
<?php echo $row['mobile'] ?>
</td>
<td style="width: 20%;">
<a style="float:left" data-toggle="modal" data-target="#memberInfo" href="<?php echo $row['id']; ?>" class="table-link clsMemberInfo view">
<span class="fa-stack">
<i class="fa fa-square fa-stack-2x"></i>
<i class="fa fa-search-plus fa-stack-1x fa-inverse"></i>
</span>
</a>
<a style="float:left" href="#" class="table-link" id="#save">
<span class="fa-stack">
<i class="fa fa-square fa-stack-2x"></i>
<i class="fa fa-pencil fa-stack-1x fa-inverse"></i>
</span>
</a>
<a href="<?php echo $row['id'] ?>" class="table-link danger delmodal" data-toggle="modal" data-target="#deleteModal">
<span class="fa-stack">
<i class="fa fa-square fa-stack-2x"></i>
<i class="fa fa-trash-o fa-stack-1x fa-inverse"></i>
</span>
</a>
</td>
</tr>
</tbody>
<div class="modal fade" id="deleteModal" class="" role="dialog">
<div class="modal-dialog modal-md">
<div class="modal-content">
<div class="modal-body text-center">
<p>Are you Sure you want to Delete ?</p>
</div>
<div class="modal-footer">
<div class="col-lg-7">
<form method="post" id="deleteForm">
<input type="hidden" id="MemberId" name="MemberId" value="<?php echo $row['id']?>">
<button type="submit" name="submit" id="yes_btn" class="btn btn-danger yes_btn">Yes</button>
</form>
<button type="button" id="no_btn" class="btn btn-success" data-dismiss="modal">No</button>
</div>
</div>
</div>
</div>
</div>
<?php
}
?>
Related
I need that when I search something in table, run again PHP script or remove table body inside then incoming AJAX response I will add in table body. How can I do that?
My PHP script like that now:
<?php
$sql = "SELECT * FROM x_crm INNER JOIN x_crm_kategori ON x_crm.k_id = x_crm_kategori.k_id WHERE durum != 3";
if (!empty(re('ara'))) {
$ara = re('ara');
$sql .= " and x_crm.unvan LIKE '%".$ara."%' OR x_crm.yetkili LIKE '%".$ara."%' OR x_crm_kategori.k_adi LIKE '%".$ara."%' OR x_crm.butce LIKE '%".$ara."%'";
}
$sql.=' LIMIT 20';
$sorgu = $db->rawQuery($sql);
if (!$sorgu) {
echo 'Data Not Found';
}
foreach ($query as $customer) {
?>
My tbody in the continuation:
<tr id="tr_<?= $musteri['id'] ?>">
<td class="text-center"><?= $musteri['id'] ?></td>
<td class="font-w600"><?= $musteri['unvan'] ?></td>
<td class="hidden-xs font-w600"><?= $musteri['yetkili'] ?></td>
<td class="hidden-xs"><?= $musteri['k_adi'] ?></td>
<td class="hidden-xs"><?= $musteri['butce'] ?></td>
<td>
<div class="btn-group hidden-xs">
<i class="fa fa-phone"></i>
<i class="fa fa-envelope"></i>
<i class="fa fa-link"></i>
<div class="btn btn-sm btn-default" data-toggle="tooltip" title="MY: <?= $musteri['yetkili'] ?>" data-original-title="MY: <?= $musteri['yetkili'] ?>"><i class="fa fa-user"></i></div>
<div class="btn btn-sm btn-warning" data-toggle="tooltip" title="Favori" data-original-title="Favori"><i class="fa fa-star"></i></div>
</div>
</td>
<td class="text-center">
<div class="btn-group hidden-xs">
<i class="fa fa-edit"></i>
<div class="col-xs-6"><label class="css-input switch switch-sm switch-success">
<input id="pasiflik_<?= $musteri['id'] ?>" data-musteri = "<?= $musteri['id'] ?>" type="checkbox" onchange="durumGuncelle(<?= $musteri['id'] ?>)" <?=($musteri['durum']=='1') ? 'checked' : ' ' ?>><span></span></label>
</div>
<i class="fa fa-times"></i>
</div>
</td>
</tr>
<?php } ?>
js :
$('#ara').click(function(){
var ara_val = $('#icerik_ara').val();
if (ara_val =="") {
console.log('Boş');
}else{
$(location).attr('href', 'https://adresgezginitasarim.com/sistem2021/admin/?modul=crm&sayfa=liste&ara='+ara_val+' ');
}
})
Sorry for my bad English, thanks in advance...
I'm open to ideas.
I have an issue with my code. I am using a model to update data, but in my form there is select option where by when I need all data to be populated I found only one row populated in it. If I have to populate values in that option by using <?php while ($row = mysqli_fetch_array($query)) {?>. All row populated in that option field but in the list where all row of data needed to be populated, it populates only one.
<?php
include('../Tools/connection.php');
$query = mysqli_query($db,"SELECT abl_atms.atmCode,abl_atms.atmID,abl_atms.branchID, abl_branch.name,abl_branch.bid
FROM abl_atms
INNER JOIN abl_branch ON abl_branch.bid = abl_atms.branchID");
while ($row = mysqli_fetch_array($query)) {
$id = $row['atmID'];
$id = $row['branchID']
?>
<tr>
<td><?php echo strtoupper($row['atmID']);?></td>
<td><?php echo ucwords($row['atmCode']).'- '.strtolower($row['name']);?></td>
<td><?php echo strtoupper($row['name']);?></td>
<td class="pull-right">
<button class="btn-success btn-xs" data-toggle="modal" href="#atm<?php echo $row['atmID'];?>"
data-toggle="tooltip" title="Edit">
<i class="fa fa-pencil-square-o" aria-hidden="true"></i></button>
<button class="btn-danger btn-xs" title="Delete" data-toggle="modal"
href="#delete<?php echo $row['atmID'];?>" data-toggle="tooltip">
<i class="fa fa-trash-o" aria-hidden="true"></i>
</button>
</td>
</tr>
<div class="modal fade" id="atm<?php echo $row['atmID'];?>" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="card" style="border-left: 4px solid coral">
<div class="card-header">
<div class="alert alert-warning" role="alert">
Update Atm information
</div>
</div>
<div class="card-body">
<form class="was-validated" action="abl_atms.php" method="POST">
<fieldset class="form-group">
<label for="exampleInputEmail1" class="bmd-label-static"><i class="fa fa-barcode" aria-hidden="true"></i> ATM CODE</label>
<input type="text" class="form-control" name="atmCode" value="<?php echo ucwords($row['atmCode']);?>" placeholder="Type ATM Identification CODE" required>
</fieldset>
<input class="form-control" name="atmID" type="hidden" value="<?php echo $row['atmID'];?>">
<fieldset class="form-group">
<label for="exampleInputEmail1" class="bmd-label-static"><i class="fa fa-snowflake-o" aria-hidden="true"></i> ATM BRANCH</label>
<select class="custom-select" required name="branchID">
<option value="">Select Branch Name</option>
<?php
while ($row = mysqli_fetch_array($query)) {
?>
<option value="<?php echo $row['branchID']; ?>"<?php if ($id == $row['branchID'])
{ echo 'selected="selected"'; } ?>><?php echo $row['name']; ?></option>
<?php
}
?>
</select>
</fieldset>
<button type="submit" class="btn btn-raised btn-warning btn-block" name="editAtm">
<i class="fa fa-floppy-o" aria-hidden="true"></i> Confirm & Update
</button>
</form>
</div>
</div>
</div>
</div>
</div>
<?php
}
?>
</tbody>
</table>
</div>
</div>
</div>
You can store results in an array and then loop over results.
$query = mysqli_query($db,"SELECT abl_atms.atmCode,abl_atms.atmID,abl_atms.branchID,abl_branch.name,abl_branch.bid
FROM abl_atms
INNER JOIN abl_branch
ON abl_branch.bid = abl_atms.branchID");
$results = mysqli_fetch_all(MYSQLI_ASSOC);
foreach($results as $v){
// Your Code....
foreach($results as $vi){
// Your Selection Options...
}
}
I'm creating a web back end for a restaurant. There is an option to block/unblock restaurant owners. I have put an "if" condition to appear button (a tag) according to the status of the restaurant owner. Within this "a" tag I want to pass the value (id) to a modal box.
I put some code in the "data-target" of "a" tag, as well as in the modal id. The value didn't pass and also didn't open the modal.
<tbody>
<?php
global $con;
$sql = "SELECT * FROM `fd_owner_details`";
$result=mysqli_query($con,$sql);
while($row=mysqli_fetch_array($result,MYSQLI_ASSOC)){
$kk=$row['id'];
?>
<tr>
<td><?php echo $row['id']; ?></td>
<td><?php echo $row['fname']. " " .$row['lname'] ; ?></td>
<td><?php echo $row['address_line1']. ", " .$row['address_line2'] ; ?></td>
<td><?php echo $row['contact_no1'].", ".$row['contact_no2']; ?></td>
<td><?php echo '<img src= "'.$row['image'].'">'; ?></td>
<td>
<?php
if ($row['status']==1){
echo "<span class='label mb-2 mb-xl-0 label-dark'>Active</span>";
}
else {
echo "<span class='label mb-2 mb-xl-0 label-light'>Disabled</span>";
}
?>
</td>
<td>
<span>
<i class="fa fa-pencil" aria-hidden="true"></i>
<?php
if ($row['status']==1){
echo '<i class="fa fa-ban" aria-hidden="true"></i>';
}
else {
echo "<a href='#' data-toggle='modal' data-target='#unblockRestaurantOwner' class='btn btn-warning btn-xs' data-toggle='tooltip' data-placement='top' data-original-title='Unblock'><i class='fa fa-check' aria-hidden='true'></i></a>";
}
?>
<i class="fa fa-trash" aria-hidden="true"></i>
</span>
</td>
</tr>
<?php } ?>
</tbody>
--------------------------------------------------------------------------------
<div class="modal fade" id="blockRestaurantOwner?id=<?php echo $row['id']; ?>" tabindex="-1" role="dialog" aria-labelledby="blockRestaurantOwnerTitle" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Confirm Delete </h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">× </span>
</button>
</div>
<div class="modal-body">
<p id="main-content">Are you sure you want to block this restaurant owner ???</p>
<p id="content">You will not be able to recover this action !!!</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">No, Cancel it </button>
<button type="button" class="btn btn-warning">Yes, Block</button>
</div>
</div>
</div>
</div>
Where Should I change, to get the "id" to the modal ?
Just copy the whole script and try to past inside a php file and try to run it. This can be modified as expected at your end using while loop.
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/js/bootstrap.min.js"></script>
</head>
<?php
$array[] = array('id'=>1, 'fname'=>'hari','lname'=>'ltest','address_line1'=>'no:9','address_line1'=>'rajan street','contact_no1'=>'92222','contact_no2'=>'899782','status'=>1);
$array[] = array('id'=>2, 'fname'=>'vvvv','lname'=>'ltest2','address_line1'=>'no:92','address_line1'=>'siv street','contact_no1'=>'522','contact_no2'=>'2922','status'=>0);
?>
<table border=1>
<tbody>
<?php foreach($array as $row){ ?>
<tr>
<td><?php echo $row['id']; ?></td>
<td><?php echo $row['fname']. " " .$row['lname'] ; ?></td>
<td><?php echo $row['address_line1']. ", " .$row['address_line2'] ; ?></td>
<td><?php echo $row['contact_no1'].", ".$row['contact_no2']; ?></td>
<td>
<?php
if ($row['status']==1){
echo "<span class='label mb-2 mb-xl-0 label-dark'>Active</span>";
}
else {
echo "<span class='label mb-2 mb-xl-0 label-light'>Disabled</span>";
}
?>
</td>
<td>
<span>
<i class="fa fa-pencil" aria-hidden="true"></i>
<?php if ($row['status']==1){ ?>
<a data-toggle="modal" href="#blockRestaurantOwner<?=$row['id']?>" class="btn btn-warning btn-xs" data-toggle="tooltip" data-placement="top" data-original-title="Block"><i class="fa fa-ban" aria-hidden="true"></i></a>
<div id="blockRestaurantOwner<?php echo $row['id']; ?>" class="modal fade" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Confirm Delete </h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">× </span>
</button>
</div>
<div class="modal-body">
<p id="main-content">Are you sure you want to block this restaurant owner ???</p>
<p id="content">You will not be able to recover this action !!!</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">No, Cancel it </button>
<button type="button" class="btn btn-warning">Yes, Block</button>
</div>
</div>
</div>
</div>
<?php }
else {
echo "<a href='#' data-toggle='modal' data-target='#unblockRestaurantOwner' class='btn btn-warning btn-xs' data-toggle='tooltip' data-placement='top' data-original-title='Unblock'><i class='fa fa-check' aria-hidden='true'></i></a>";
}
?>
<i class="fa fa-trash" aria-hidden="true"></i>
</span>
</td>
</tr>
<?php } ?>
</tbody>
</table>
you can set onclick listener to block button and pass owner id to that function like below
<tbody>
<?php
global $con;
$sql = "SELECT * FROM `fd_owner_details`";
$result=mysqli_query($con,$sql);
while($row=mysqli_fetch_array($result,MYSQLI_ASSOC)){
$kk=$row['id'];
?>
<tr>
<td><?php echo $row['id']; ?></td>
<td><?php echo $row['fname']. " " .$row['lname'] ; ?></td>
<td><?php echo $row['address_line1']. ", " .$row['address_line2'] ; ?></td>
<td><?php echo $row['contact_no1'].", ".$row['contact_no2']; ?></td>
<td><?php echo '<img src= "'.$row['image'].'">'; ?></td>
<td>
<?php
if ($row['status']==1){
echo "<span class='label mb-2 mb-xl-0 label-dark'>Active</span>";
}
else {
echo "<span class='label mb-2 mb-xl-0 label-light'>Disabled</span>";
}
?>
</td>
<td>
<span>
<i class="fa fa-pencil" aria-hidden="true"></i>
<?php
if ($row['status']==1){
echo '<i class="fa fa-ban" aria-hidden="true"></i>';
}
else {
echo "<a href='#' data-toggle='modal' data-target='#unblockRestaurantOwner' class='btn btn-warning btn-xs' data-toggle='tooltip' data-placement='top' data-original-title='Unblock'><i class='fa fa-check' aria-hidden='true'></i></a>";
}
?>
<i class="fa fa-trash" aria-hidden="true"></i>
</span>
</td>
</tr>
<?php } ?>
</tbody>
<div class="modal fade" id="blockRestaurantOwner" tabindex="-1" role="dialog" aria-labelledby="blockRestaurantOwnerTitle" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Confirm Delete </h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">× </span>
</button>
</div>
<div class="modal-body">
<p id="main-content">Are you sure you want to block this restaurant owner ???</p>
<p id="content">You will not be able to recover this action !!!</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">No, Cancel it </button>
<button type="button" class="btn btn-warning">Yes, Block</button>
</div>
</div>
</div>
</div>
<script type="text/javascript">
var target_owner_id="";
function set_target_id(id){
target_owner_id = id;
console.log(target_owner_id);
}
</script>
Basically I have this code where I want to extract some data from a database and display it on a pop-up window. The problem is when I click on the eye icon ( labelled More ) I want it to display the correspondent id of that table row but I can't seem to figure out how to do that.
For more references I set up a temporary website to better see the problem : http://twgtest-org.stackstaging.com/bau50/bau50_extract.php
You can see that when I click on more the displayed ID is actually all the IDs from the database instead of it being only the ID of that row
<?php
//load database connection
$pdo = new PDO("mysql:host=$host;dbname=$database_name", $user, $password, array(
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
));
$query_string = "SELECT * FROM bau50";
$query = $pdo->prepare($query_string);
$query->execute();
?>
<body>
<div class="container">
<ul class="text-align">
<?php
if (!$query->rowCount() == 0) {
while ($show_all = $query->fetch()) {
echo '<tr><th scope="row">';
echo $show_all['id_Bau50'];
echo '</th><td>';
echo $show_all['name'];
echo '</td><td>';
echo $show_all['produkt'];
echo '</td><td>';
echo $show_all['preis']," €";
echo '</th><td>';
echo $show_all['Ergebniss'];
echo '</td>
<td><p data-placement="top" data-toggle="tooltip" title="more"><button class="btn btn-primary btn-xs" data-title="more" data-toggle="modal" data-target="#more" ><span class="fa fa-eye"></span></button></p></td>
<td><p data-placement="top" data-toggle="tooltip" title="Edit"><button class="btn btn-secondary btn-xs" data-title="Edit" data-toggle="modal" data-target="#edit" ><span class="fa fa-pencil"></span></button></p></td>
<td><p data-placement="top" data-toggle="tooltip" title="Delete"><button class="btn btn-danger btn-xs" data-title="Delete" data-toggle="modal" data-target="#delete" ><span class="fa fa-trash"></span></button></p></td></tr>';
}
echo '</tbody></table>';
}
?></ul>
</div>
<?php
$query_view = "SELECT * FROM bau50";
$query2= $pdo->prepare($query_view);
$query2->execute();
echo'<div class="modal fade" id="more" tabindex="-1" role="dialog" aria-labelledby="more" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true"><span class="fa fa-remove" aria-hidden="true"></span></button>
<h4 class="modal-title custom_align" id="Heading">More</h4>
</div>
<div class="modal-body">
<div>';
while ($show= $query2->fetch()) {
$id= $show ['id_Bau50'];
echo $id;
}
echo '</div>
<div class="modal-footer ">
<button type="button" class="btn btn-secondary btn-lg" style="width: 100%;" data-toggle="modal" data-target="#edit"><span class="fa fa-pencil"></span> Update</button>
</div>
</div>
<!-- /.modal-content -->
</div>
<!-- /.modal-dialog -->
</div>
</div>';
?>
This is the very simply solution: add a new modal for each row identified by its id for example for id "4" you will open the modal with id "modal4" and so on:
<?php
//load database connection
$pdo = new PDO("mysql:host=$host;dbname=$database_name", $user, $password, array(
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
));
$query_string = "SELECT * FROM bau50";
$query = $pdo->prepare($query_string);
$query->execute();
?>
<body>
<div class="container">
<ul class="text-align">
<?php
if (!$query->rowCount() == 0) {
while ($show_all = $query->fetch()) {
echo '<tr><th scope="row">';
echo $show_all['id_Bau50'];
echo '</th><td>';
echo $show_all['name'];
echo '</td><td>';
echo $show_all['produkt'];
echo '</td><td>';
echo $show_all['preis']," €";
echo '</th><td>';
echo $show_all['Ergebniss'];
echo '</td>
<td><p data-placement="top" data-toggle="tooltip" title="more"><button class="btn btn-primary btn-xs" data-title="more" data-toggle="modal" data-target="#more'.$show_all['id_Bau50'].'" ><span class="fa fa-eye"></span></button></p></td>
<td><p data-placement="top" data-toggle="tooltip" title="Edit"><button class="btn btn-secondary btn-xs" data-title="Edit" data-toggle="modal" data-target="#edit" ><span class="fa fa-pencil"></span></button></p></td>
<td><p data-placement="top" data-toggle="tooltip" title="Delete"><button class="btn btn-danger btn-xs" data-title="Delete" data-toggle="modal" data-target="#delete" ><span class="fa fa-trash"></span></button></p></td></tr>';
}
echo '</tbody></table>';
}
?></ul>
</div>
<?php
$query_view = "SELECT * FROM bau50";
$query2= $pdo->prepare($query_view);
$query2->execute();
while ($show= $query2->fetch()) {
$id= $show ['id_Bau50'];
echo'<div class="modal fade" id="more'.$id.'" tabindex="-1" role="dialog" aria-labelledby="more" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true"><span class="fa fa-remove" aria-hidden="true"></span></button>
<h4 class="modal-title custom_align" id="Heading">More</h4>
</div>
<div class="modal-body">
<div>';
echo $id;
echo '</div>
<div class="modal-footer ">
<button type="button" class="btn btn-secondary btn-lg" style="width: 100%;" data-toggle="modal" data-target="#edit"><span class="fa fa-pencil"></span> Update</button>
</div>
</div>
<!-- /.modal-content -->
</div>
<!-- /.modal-dialog -->
</div>
</div>';
}
?>
This is ok for not so many rows or if you don't want to write some javascript.
A nicer solution would be to use one single modal with all content inside and show/hide the selected one, for this you need to use some js code and don't use the standard bootstrap attribute-driven methods.
In this example I'm using jquery and js code (se at the bottom).
<?php
//load database connection
$pdo = new PDO("mysql:host=$host;dbname=$database_name", $user, $password, array(
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
));
$query_string = "SELECT * FROM bau50";
$query = $pdo->prepare($query_string);
$query->execute();
?>
<body>
<div class="container">
<ul class="text-align">
<?php
if (!$query->rowCount() == 0) {
while ($show_all = $query->fetch()) {
echo '<tr><th scope="row">';
echo $show_all['id_Bau50'];
echo '</th><td>';
echo $show_all['name'];
echo '</td><td>';
echo $show_all['produkt'];
echo '</td><td>';
echo $show_all['preis']," €";
echo '</th><td>';
echo $show_all['Ergebniss'];
echo '</td>
<td><p data-placement="top" data-toggle="tooltip" title="more"><button class="btn btn-primary btn-xs" data-moreid="'.$show_all['id_Bau50'].'" ><span class="fa fa-eye"></span></button></p></td>
<td><p data-placement="top" data-toggle="tooltip" title="Edit"><button class="btn btn-secondary btn-xs" data-title="Edit" data-toggle="modal" data-target="#edit" ><span class="fa fa-pencil"></span></button></p></td>
<td><p data-placement="top" data-toggle="tooltip" title="Delete"><button class="btn btn-danger btn-xs" data-title="Delete" data-toggle="modal" data-target="#delete" ><span class="fa fa-trash"></span></button></p></td></tr>';
}
echo '</tbody></table>';
}
?></ul>
</div>
<div class="modal fade" id="more" tabindex="-1" role="dialog" aria-labelledby="more" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true"><span class="fa fa-remove" aria-hidden="true"></span></button>
<h4 class="modal-title custom_align" id="Heading">More</h4>
</div>
<div class="modal-body">
<?php
$query_view = "SELECT * FROM bau50";
$query2= $pdo->prepare($query_view);
$query2->execute();
while ($show= $query2->fetch()) {
$id= $show ['id_Bau50'];
echo '<div id="more'.$id.'">'.$id.'</div>';
}
?>
</div>
<div class="modal-footer ">
<button type="button" class="btn btn-secondary btn-lg" style="width: 100%;" data-toggle="modal" data-target="#edit"><span class="fa fa-pencil"></span> Update</button>
</div>
</div>
<!-- /.modal-content -->
</div>
<!-- /.modal-dialog -->
</div>
<!-- YOU NEED JQUERY FOR THIS: -->
<script src="https://code.jquery.com/jquery-2.2.4.min.js"></script>
<script type="text/javascript">
$(function(){
$("button[data-moreid]").click(function(){
$("#more .modal-body > div").hide(); //hide all more div
var id=$(this).attr("data-moreid"); //get id from pushed button
$("#more .modal-body #more"+id).show(); //show only pushed id
$("#more").modal("show"); //show modal
});
});
</script>
I know here are some similar Topics but I couldn't find a solution for my problem.
I have a table where I have a delete button for every entry (in code called "wp"). When I click this button a modal opens. In this model, I want to Show some data for which I Need to pass the ID of the item I want to delete to the Controller, where I pass it to a function which includes a database query and finally Needs to get the right value back to the view.
View:
<tbody>
<?php
if($wps!= NULL){
foreach($wps as $wp){
?>
<tr>
<td><?php echo $wp->type; ?></td>
<td>....</td>
<a class="btn btn-default btn-icon" title="Edit" href="<?php echo site_url("myurl"); ?>"><i class="icon icon-edit" aria-hidden="true"></i></a>
<a class="btn btn-default btn-icon" title="Create" href="<?php echo site_url("myurl"); ?>"><i class="icon icon-add" aria-hidden="true"></i></a>
<button value="<?php echo $wp->id; ?>" class="btn btn-default btn-icon delete" title="Delete" data-toggle="modal" data-target="#modal-delete-<?php echo $wp->id; ?>" type="button"><i class="icon icon-move-to-trash" aria-hidden="true"></i></button>
</td>
</tr>
<div id="modal-delete-<?php echo $wp->id; ?>" class="modal fade" aria-labelledby="exampleModalLabel2" aria-hidden="true" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<button type="button" class="close" data-dismiss="modal">
<span aria-hidden="true">x</span>
<span class="sr-only">Close</span>
</button>
<div class="modal-header">
<h4 class="modal-title" id="exampleModalLabel2"><strong>Delete </strong><br><br>Account: <strong><?php echo $cus->name ?></strong><br>: <strong><?php echo $wp->type ?></strong><br>Service in Scope: <strong><?php echo $wp->sis?></strong><br>This cannot be undone. Do you want to continue?</h4>
<ul class="content-list">
<?php
if($finding != NULL){
foreach($finding as $f){
?>
<ul class="content-list">
<li class="media">
<div class="media-body">
<div class="media-heading"><?php echo $f->sis?></div>
<div class="media-hint"><?php echo $f->finding ?></div>
</div>
</li>
</div>
<?php }} ?>
</ul>
</div>
<div class="modal-footer">
<br>
<center>
<a href="<?php echo site_url("myurl"); ?>" class="btn btn-brand" title="Delete" style="width: 170px;">
<div align="center"><i class="icon icon-confirm" aria-hidden="true"></i> Delete</div>
</a>
<button type="button" class="btn btn-brand" title="Return" data-dismiss="modal" style="width: 170px;">
<div align="center"><i class="icon icon-cancel" aria-hidden="true"></i> Return</div>
</button>
</center>
</div>
</div>
</div>
</div>
<?php }} ?>
</tbody>
Controller:
$data["finding"] = $this->Model->get_findings($needed_value);
It would be great if you have an idea how I can pass the $wp->id from view to controller
Using ajax and Jquery you can pass the values. Anyway you are using modal popup, so its is easy. Check the possibilities of modal popup.
Sending data to a controller. one way is to Do it using a link. This is an example. The $id gives the link to the controller. Then you use the ID from your db as the link(anchor). The $ID could be a link to a controller that deletes the data in the db
<?php foreach($getlist as $row)
{
$id = "forms/fill_form/$row->id";
$this->table->add_row(
anchor($id, $row->id),
$row->title,
$row->date,
$row->parent,
$row->status
);
}