I have a modal and after clicking on the Visualizar option I want it to load information from a table.
However, it only loads the first table ID, regardless of which item of the table I want to view. It always shows the same information.
Below is the code I'm using.
<div class="container-fluid">
<table class="table table-striped" data-toggle="table"
data-search="true"
data-show-refresh="true"
data-show-columns="true">
<thead>
<tr>
<th class="th-small" data-align="left" data-sortable="true">ID</th>
<th data-align="left" data-sortable="true">Nome</th>
<th class="th-small">Ações</th>
</tr>
</thead>
<tbody>
<?php
foreach ($idade as $key => $v) {
?>
<tr>
<td><?= $v->id ?></td>
<td><?= $v->titulo ?></td>
<td>
<form data-toggle="validator" method="POST" enctype="multipart/form-data">
<div class="dropdown">
<button class="btn btn-default dropdown-toggle" type="submit" data-toggle="dropdown">... <span class="caret"></span></button>
<ul class="table-modal dropdown-menu">
<li class=""><a data-toggle="modal" data-target="#modal-select">Visualizar</a></li>
<li><a data-toggle="modal" data-target="#editarIdade">Editar</a></li>
</ul>
</div>
</td>
</tr>
<?php } ?>
</tbody>
</table>
<!-- Modal VISUALIZAR -->
<div class="modal fade" id="modal-select" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="cadastroIdadelLabel">Visualizar - Idade</h4>
</div>
<div class="modal-body">
<form class="form-inline" role="form" data-toggle="validator" action="Idade/page/visualizar">
<fieldset>
<div class="form-group">
<div>
<label>Idade:</label>
<?= $v->titulo ?>
</div>
<div>
<label>Código:</label>
<?= $v->id ?>
</div>
</div>
</fieldset>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Voltar</button>
</div>
</form>
</div>
</div>
</div>
Could anyone help me find the issue?
First, you have open <form> tag inside foreach code (Sidenote: He doesn't need a form here)
<?php foreach ($idade as $key => $v) {?>
<tr>
<td><?= $v->id ?></td>
<td><?= $v->titulo ?></td>
<td>
<form data-toggle="validator" method="POST" enctype="multipart/form-data">
<div class="dropdown">
<button class="btn btn-default dropdown-toggle" type="submit" data-toggle="dropdown">... <span class="caret"></span></button>
<ul class="table-modal dropdown-menu">
<li class=""><a data-toggle="modal" data-target="#modal-select">Visualizar</a></li>
<li><a data-toggle="modal" data-target="#editarIdade">Editar</a></li>
</ul>
</div>
</form>
</td>
</tr>
<?php } ?>
Second you have to put <form> tag before modal-body inside Modal (sidenote: <?= $v->titulo ?> and <?= $v->id ?> will not show any value outside foreach
<div class="modal fade" id="modal-select" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="cadastroIdadelLabel">Visualizar - Idade</h4>
</div>
<form class="form-inline" role="form" data-toggle="validator" action="Idade/page/visualizar">
<div class="modal-body">
<fieldset>
<div class="form-group">
<div>
<label>Idade:</label>
<?= $v->titulo ?>
</div>
<div>
<label>Código:</label>
<?= $v->id ?>
</div>
</div>
</fieldset>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Voltar</button>
</div>
</form>
</div>
</div>
</div>
Third you have to add the id <?= $v->id ?> as data attribute data-id="<?= $v->id ?>" to modal trigger button and with BS Modal event, pass it to modal when modal shown
<li class=""><a data-id="<?= $v->id ?>" data-toggle="modal" data-target="#modal-select">Visualizar</a></li>
Modal show event.
$(document).ready(function(){
$('#modal-select').on('show.bs.modal', function (e) {
var id = $(e.relatedTarget).data('id');
alert(id);
//pass `id` to input, HTML selector do what ever you like with it
});
});
Fourth, To fetch data against id from database and show in modal, have a look at this answer.
You can ask if needs more explanation or help with any step.
Related
I have a problem with a bootstrap modal. I'm using PHP.
In an admin panel there is a table with the list of the users and the possibility to edit or delete a user's profile. For the delete I want to create a modal for the confirm of the delete but, when I click on "confirm" button inside the modal, the modal gets by default the user ID of the first user in the table and not the user ID of the selected user.
Here is the code:
<?php foreach ($utenti as $utente) { ?>
<tr>
<th scope="row"> <?php echo $utente['idUser']?> </th>
<td><?php echo $utente['nome']." ".$utente['cognome']?></td>
<?php if($_SESSION['role'] == 1) {?>
<td><?php echo $utente['az']?></td>
<?php } ?>
<td><?php echo $utente['email']?></td>
<td class="text-warning"><a
href="<?php echo 'editUser.php?user='.$utente['idUser']?>"><i
class="fas fa-edit text-warning"></i></a></td>
<!-- <td class="text-warning"><i class="fas fa-trash-alt text-danger"></i></td> -->
<td class="text-danger">
<button type="button" class="btn" data-toggle="modal"
data-target="#confirmDelete"><i
class="fas fa-trash-alt text-danger"></i><?php var_dump($utente['idUser']); ?>
</button>
</td>
<div class="modal" tabindex="-1" role="dialog" id="confirmDelete">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">
Attenzione <?php var_dump($utente['idUser']); ?></h5>
<button type="button" class="close" data-dismiss="modal"
aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<p>Continuando eliminerai l'utente in maniera irreversibile</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-danger "
><a
class="text-white btn-modal-confirm"
href="<?php echo '?action=delete&user='.$utente['idUser']?>"
>Elimina</a>
</button>
<button type="button" class="btn btn-secondary" data-dismiss="modal">
Indietro
</button>
</div>
</div>
</div>
</div>
</tr>
<?php }?>
If I make a var_dump of $utente['idUser'] before the modal, it gets the right user ID. If I make it inside the modal it gets by default the first ID, as I said.
Notice that every modal trigger button has a data-target attribute to define which modal will be opened.
In your case, the button of every row you used to triggered the modal have the same data-target, which is #confirmDelete. These modals behind also has the same id called #confirmDelete, so every time you hit the modal trigger button (all had the same data-target) then eventually it will shows up the very first modal element.
For a better understanding, compare my code to yours and see the differences.
<?php foreach ($utenti as $utente) { ?>
<tr>
<th scope="row"> <?php echo $utente['idUser']?> </th>
<td><?php echo $utente['nome']." ".$utente['cognome']?></td>
<?php if($_SESSION['role'] == 1) {?>
<td><?php echo $utente['az']?></td>
<?php } ?>
<td><?php echo $utente['email']?></td>
<td class="text-warning"><a
href="<?php echo 'editUser.php?user='.$utente['idUser']?>"><i
class="fas fa-edit text-warning"></i></a></td>
<!-- <td class="text-warning"><i class="fas fa-trash-alt text-danger"></i></td> -->
<td class="text-danger">
<button type="button" class="btn" data-toggle="modal"
data-target="#confirmDelete_<?php echo $utente['idUser']; ?>"><i
class="fas fa-trash-alt text-danger"></i><?php var_dump($utente['idUser']); ?>
</button>
</td>
<div class="modal" tabindex="-1" role="dialog" id="confirmDelete_<?php echo $utente['idUser']; ?>">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">
Attenzione <?php echo $utente['idUser']; ?></h5>
<button type="button" class="close" data-dismiss="modal"
aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<p>Continuando eliminerai l'utente in maniera irreversibile</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-danger "
><a
class="text-white btn-modal-confirm"
href="<?php echo '?action=delete&user='.$utente['idUser']?>"
>Elimina</a>
</button>
<button type="button" class="btn btn-secondary" data-dismiss="modal">
Indietro
</button>
</div>
</div>
</div>
</div>
</tr>
<?php }?>
In the above code, I gave every pair of modal elements (modal trigger button and modal ID) a unique data-target value and a unique element id.
...
<button type="button" class="btn" data-toggle="modal"
data-target="#confirmDelete_<?php echo $utente['idUser']; ?>">
...
<div class="modal" tabindex="-1" role="dialog" id="confirmDelete_<?php echo $utente['idUser']; ?>">
...
Now each pair of modal elements have their own ids and they should be working the way you wanted.
I have this template
<template>
<div class="main">
<div class="container-fluid" style="padding-top: 2.5%">
<h4 class="page-title"><i class="lnr lnr-funnel"> </i> Infusionsoft Accounts
<button #click="addInfusionsoft" class="btn btn-xs btn-success" ><i class="lnr lnr-plus-circle"> </i> New </button>
</h4>
<div class="row">
<div class="col-md-12">
<table class="table table-responsive table-bordered table-striped">
<tr>
<th>ID</th>
<th>App Name</th>
<th>Auth Key</th>
<th>Status</th>
<th>Created</th>
<th>Updated</th>
<th width="300px">Action</th>
</tr>
</table>
</div>
</div>
<div class="modal fade" id="modalAddAccount" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog" role="document">
<form method="POST" action="" id="addInfsAccount"/>
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="myModalLabel">Infusionsoft Account</h4>
</div>
<div class="modal-body">
<p class="small">Fill up the form to add a new Infusionsoft Account.</p>
<br/>
<div class="form-group row">
<div class="col-md-8 col-md-offset-2">
<input id="appName" type="text" required placeholder="App Name e.g l328" class="form-control" name="appName">
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-primary">Add Account</button>
</div>
</div>
</form>
</div>
</div>
<app-legend/>
</div>
</div>
</template>
<script>
import Legend from "./Legend";
import NavBar from "../layouts/NavBar";
import SideBar from "../layouts/SideBar";
export default {
data() {
return {
infsModal: false,
}
},
created() {
},
components: {
'app-legend': Legend,
'nav-bar': NavBar,
'side-bar': SideBar,
},
methods: {
addInfusionsoft() {
$('#modalAddAccount').modal('show');
}
},
}
</script>
I'm using this template for the project https://www.themeineed.com/downloads/klorofil-free-bootstrap-admin-template/, I kept everything as default and didn't have any major modifications with the bootstrap classes. If I use jquery function to call the modal it will show correctly, however moving the modal to another template and calling is by using v-model and v-if, nothing really happens. Please see sample below
parent template
<template>
<div class="main">
<div class="container-fluid" style="padding-top: 2.5%">
<h4 class="page-title"><i class="lnr lnr-funnel"> </i> Infusionsoft Accounts
<button #click="infsModal = true" class="btn btn-xs btn-success" ><i class="lnr lnr-plus-circle"> </i> New </button>
</h4>
<div class="row">
<div class="col-md-12">
<table class="table table-responsive table-bordered table-striped">
<tr>
<th>ID</th>
<th>App Name</th>
<th>Auth Key</th>
<th>Status</th>
<th>Created</th>
<th>Updated</th>
<th width="300px">Action</th>
</tr>
</table>
</div>
</div>
<div v-if="infsModal">
<div class="modal fade" id="modalAddAccount" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog" role="document">
<form method="POST" action="" id="addInfsAccount"/>
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="myModalLabel">Infusionsoft Account</h4>
</div>
<div class="modal-body">
<p class="small">Fill up the form to add a new Infusionsoft Account.</p>
<br/>
<div class="form-group row">
<div class="col-md-8 col-md-offset-2">
<input id="appName" type="text" required placeholder="App Name e.g l328" class="form-control" name="appName">
<span v-if="false" span class="invalid-feedback">
<strong>Error</strong>
</span>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-primary">Add Account</button>
</div>
</div>
</form>
</div>
</div>
</div>
<app-legend/>
</div>
</div>
</template>
<script>
import Legend from "./Legend";
import NavBar from "../layouts/NavBar";
import SideBar from "../layouts/SideBar";
import InfusionsoftAdd from "../infusionsoft/InfusionsoftAdd";
export default {
data() {
return {
infsModal: false,
}
},
created() {
},
components: {
'app-legend': Legend,
'nav-bar': NavBar,
'side-bar': SideBar,
'infs-modal': InfusionsoftAdd,
},
methods: {
addInfusionsoft() {
//this.$router.push('/infusionsoft')
}
},
}
</script>
this is the modal:
<template>
<div v-if="dialog">
<transition name="modal">
<div class="modal fade" id="modalAddAccount" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog" role="document">
<form method="POST" action="" id="addInfsAccount"/>
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="myModalLabel">Infusionsoft Account</h4>
</div>
<div class="modal-body">
<p class="small">Fill up the form to add a new Infusionsoft Account.</p>
<br/>
<div class="form-group row">
<div class="col-md-8 col-md-offset-2">
<input id="appName" type="text" required placeholder="App Name e.g l328" class="form-control" name="appName">
<span v-if="false" span class="invalid-feedback">
<strong>Error</strong>
</span>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-primary">Add Account</button>
</div>
</div>
</form>
</div>
</div>
</transition>
</div>
</template>
<script>
export default {
data() {
return {
dialog: true
}
},
methods: {
back() {
//this.$router.back();
}
}
}
</script>
Is there anything I'm doing wrong?
When you set infsModal to true, all that's happening is that you're including the modal code but you're still not displaying the modal. You can still use jQuery here if you'd like, no reason not to. You can remove the infsModal variable since it's not needed (the modal won't display even if that's set to true... you still need to tell Bootstrap to actually show the modal). If you want to get away from jQuery, a solid option is Bootstrap-Vue https://bootstrap-vue.org/docs/components/modal ... let me know if that helps!
I'm storing data from mysql in SESSION and passing it to another page where I make zip with all data's and download it. So far everything work just perfect.
Now I'm trying to make when user click on download button before to make actual download to enter name for the zip archive in modal window and then download the archive. So far I've made the modal but now I can't figured it out how to pass the input field text into the session. All other data is passed correctly. Here is the source so far
if(! isset($_POST['showcart'])) exit;
echo '<a class="btn btn-danger btn-lg pull-right" style="margin: 10px;" data-toggle="modal" data-target="#myModalNorm">Download All Files</a>
<table class="table table-striped table-bordered table-condensed responsive" id="sort">
<thead>
<tr>
<th>ID</th>
<th>Title</th>
<th>Description</th>
<th>Action</th>
</tr>
</thead>';
foreach ($_SESSION['itemid'] as $i):
$sql = "SELECT * FROM uploads WHERE upload_id = :id";
$result = $pdo->prepare($sql);
$result->bindParam(":id", $i);
$result->execute();
$resArray = $result->fetchAll();
foreach ( $resArray as $row ):?>
<div class="row">
<div class="box-content">
<tbody>
<tr>
<td class="center"><?=$row["upload_id"]?></td>
<td class="center"><?=$row["upload_title"]?></td>
<td class="center"><?=$row["upload_description"]?></td>
</tr>
</tbody>
</div>
</div>
<!-- Modal -->
<div class="modal fade" id="myModalNorm" tabindex="-1" role="dialog"
aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<!-- Modal Header -->
<div class="modal-header">
<button type="button" class="close"
data-dismiss="modal">
<span aria-hidden="true">×</span>
<span class="sr-only">Close</span>
</button>
<h4 class="modal-title" id="myModalLabel">
Please enter the name for the archive
</h4>
</div>
<!-- Modal Body -->
<div class="modal-body">
<form role="form">
<div class="form-group">
<label for="exampleInputEmail1"></label>
<input type="text" class="form-control"
id="archiveName" placeholder="Please enter the name for the archive"/>
</div>
</form>
</div>
<!-- Modal Footer -->
<div class="modal-footer">
<button type="button" class="btn btn-default"
data-dismiss="modal">
Close
</button>
<a href="create_zip.php" class="btn btn-primary">
Download
</a>
</div>
</div>
</div>
</div>
<?php endforeach;?>
<?php endforeach; ?>
</table> </div>
On the create_zip.php I take all from $_SESSION['itemid'] but this <input type="text" class="form-control" id="archiveName" placeholder="Please enter the name for the archive"/>
How to take also this input?
You can achieve this quite easy actually. Firstly wrap your table around <form></form>
So it will happen something like this
if(! isset($_POST['showcart'])) exit;
echo '<form action="create_zip.php" method="post">
<a class="btn btn-danger btn-lg pull-right" style="margin: 10px;" data-toggle="modal" data-target="#myModalNorm">Download All Files</a>
<table class="table table-striped table-bordered table-condensed responsive" id="sort">
<thead>
....
<!-- Modal Body -->
<div class="modal-body">
<div class="form-group">
<label for="archiveName"></label>
<input type="text" class="form-control"
id="archiveName" name="archiveName" placeholder="Please enter the name for the archive"/>
</div>
</div>
<!-- Modal Footer -->
<div class="modal-footer">
<button type="button" class="btn btn-default"
data-dismiss="modal">
Close
<input type="submit" name="submit" value="Download" class="btn btn-primary">
</div>
</div>
</div>
</div>
<?php endforeach;?>
<?php endforeach; ?>
</table> </div></form>
Then in create_zip.php just check if isset submit button and assign variable.
if(isset($_POST['submit']))
{
//your code
$archiveName = $_POST['archiveName'];
// other source
} else { echo 'no archive'; }
I have my data displayed in table, and the way to edit and delete the data is in bootstrap modal. I'll just showing my delete modal. I used CodeIgniter 2.2.6:
My table:
<table class="table table-striped table-bordered table-hover">
<thead class="text-center">
<th class="text-center">No.</th>
<th class="text-center">Major Code</th>
<th class="text-center">Major Name</th>
<th class="text-center">Option</th>
</thead>
<tbody>
<?php $no = 1; ?>
<?php foreach ($select_major as $row): ?>
<tr>
<td><?php echo $no++; ?></td>
<td><?php echo $row->cd_major; ?></td>
<td><?php echo $row->name_major; ?></td>
<td align=center>
<!-- DELETE BUTTON -->
<a
class="btn btn-danger btn-xs"
role="button"
data-toggle="modal"
data-target="#modal-delete"
href="<?php
$cd_major = $row->cd_major;
$name_major = $row->name_major;
?>">
<i class="fa fa-fw fa-trash"></i> Delete
</a>
</td>
</tr>
<?php endforeach; ?>
</tbody>
My Modal:
<!-- MODAL DELETE DATA -->
<div class="modal fade" id="modal-delete" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
<form class="form-horizontal" method="POST" action="<?php echo base_url('major'); ?>">
<input type="hidden" name="id_major" value="<?php echo (isset($id_major) ? $id_major : ''); ?>" />
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<!-- MODAL TITLE -->
<h4 class="modal-title"><i class="fa fa-fw fa-trash"></i> Delete Data</h4>
</div>
<!-- FORM -->
<div class="modal-body">
<p>Are you sure to delete this major? <b><?php echo $name_major; ?></b> ini?</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default pull-left" data-dismiss="modal">Close</button>
<input type="submit" class="btn btn-danger" name="delete" value="Yes, delete" />
</div>
</form>
</div><!--/ .modal-content -->
</div><!--/ .modal-dialog -->
</div><!--/ .modal -->
But when I try to delete the selected data, it always ordering to delete the last data. What should I do to fix it?
In your case you would add code something like below:
Your new table:
<table class="table table-striped table-bordered table-hover">
<thead class="text-center">
<th class="text-center">No.</th>
<th class="text-center">Major Code</th>
<th class="text-center">Major Name</th>
<th class="text-center">Option</th>
</thead>
<tbody>
<?php $no = 1; ?>
<?php foreach ($select_major as $row): ?>
<tr>
<td><?php echo $no++; ?></td>
<td><?php echo $row->cd_major; ?></td>
<td><?php echo $row->name_major; ?></td>
<td align=center>
<!-- DELETE BUTTON -->
<a
class="btn btn-danger btn-xs"
role="button"
data-toggle="modal"
data-target="#modal-delete"
href="<?php
$cd_major = $row->cd_major;
$name_major = $row->name_major;
?>" onclick=deleteRecord(<?php $row->cd_major?>)>
<i class="fa fa-fw fa-trash"></i> Delete
</a>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<script>
function deleteRecord(id){
document.getElementById("id_major").value = id;
}
</script>
Your new modal:
<!-- MODAL DELETE DATA -->
<div class="modal fade" id="modal-delete" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
<form class="form-horizontal" method="POST" action="<?php echo base_url('major'); ?>">
<input type="hidden" name="id_major" id="id_major" value="<?php echo (isset($id_major) ? $id_major : ''); ?>" />
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<!-- MODAL TITLE -->
<h4 class="modal-title"><i class="fa fa-fw fa-trash"></i> Delete Data</h4>
</div>
<!-- FORM -->
<div class="modal-body">
<p>Are you sure to delete this major? <b><?php echo $name_major; ?></b> ini?</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default pull-left" data-dismiss="modal">Close</button>
<input type="submit" class="btn btn-danger" name="delete" value="Yes, delete" />
</div>
</form>
</div><!--/ .modal-content -->
</div><!--/ .modal-dialog -->
</div><!--/ .modal -->
Please use the code which i have given you, it should work now.
I assume cd_major is the id of the row which you want to delete, if not, you can replace the field name in the function which we have added to <a> tag in onclick event.
Thanks
I have been scratching my head about this for days and i cant seem to understand why this isnt working,
i have a modal which pops up when selecting the accept button, this modal should populate the users name and telephone number.
the problem is that when you select the accept it only populate the first persons details and no the rest of the people in the table, i dont understand why if anyone can point out why i would be much obliged
here is my code (sorry its abit messy at the moment):
<?php
require_once ("includes/session_check.php");
require_once ("includes/db_connect.php");
//MySqli Select Query
$results = $mysqli->query("SELECT id, username, phone, requester,goodorbad,confirmed,denied FROM request WHERE goodorbad=1 AND confirmed=0 AND denied=0 Order by ID ASC");
echo '
<!-- **********************************************************************************************************************************************************
MAIN CONTENT
*********************************************************************************************************************************************************** -->
<!--main content start-->
<section id="main-content">
<section class="wrapper site-min-height">
<h3><i class="fa fa-angle-right"></i> Non Authenticated Requests</h3>
<div class="row mt">
<div class="col-lg-12">
<p>Non Authenticated Requests here.</p>';
echo '<div class="row mt">
<div class="col-md-12">
<div class="content-panel">
<table class="table table-striped table-advance table-hover">
<h4><i class="fa fa-angle-right"></i>Non Authenticated Requests</h4>
<hr> <thead>
<tr>
<th><i class="fa fa-bullhorn"></i>Username</th>
<th><i class="fa fa-phone"></i>Phone number update request</th>
<th><i class="fa fa-bookmark"></i>Requester</th>
<th><i class=" fa fa-edit"></i> Status</th>
<th><i class=" fa fa-edit"></i> Accept/Decline</th>
<th></th>
</tr>
</thead>';
while($row = $results->fetch_object()) {
//$row->id
//$row->confirmed
//$row->denied
$status = $row->confirmed;
echo '
<!-- Modal for Confirm -->
<form action="#" method="POST">
<div aria-hidden="true" aria-labelledby="myModalLabel" role="dialog" tabindex="-1" id="myModal" class="modal fade">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<input type="hidden" name="username_request" value="'.$row->username.'"/>
<input type="hidden" name="telephone_request" value="'.$row->phone.'"/>
<h4 class="modal-title">Are you sure ?</h4>
</div>
<div class="modal-body">
<br>
<p>You are about to update </p>
'.$row->username.'
<br>
<p> with the following telephone number </p>
'.$row->phone.'
<div class="modal-footer">
<button data-dismiss="modal" class="btn btn-default"
type="button">Cancel</button>
<button data-dismiss="modal" class="btn btn-default"
type="button">Submit</button>
</div>
</div>
</div>
</div>
</form>
<!-- modal -->
<tbody>
<tr>
<td>'.$row->username.'</td>
<td>'.$row->phone.'</td>
<td>'.$row->requester.' </td>';
if($status == 1){
echo ' <td><span class="label label-success">Completed</span></td>
<td></td>
<td></td>
';
}else{
}
echo '<td><span class="label label-info label-mini">Pending</span></td>
<td>
Accept?
<a data-toggle="modal" href="#myModal"> <button class="btn btn-success btn-xs"><i class="fa fa-check"></i></button>
</a>
<td>
Decline?
<button class="btn btn-danger btn-xs"><i class="fa fa-minus-circle"></i></button>
</td>
</td>
</tr>
</tbody>
';
}
echo '
</table>
</div><!-- /content-panel -->
</div><!-- /col-md-12 -->
</div><!-- /row -->';
// close connection
$mysqli->close();
?>
<html>
</html>
You need to add unique id to every model.
Try
<?php
require_once ("includes/session_check.php");
require_once ("includes/db_connect.php");
//MySqli Select Query
$results = $mysqli->query("SELECT id, username, phone, requester,goodorbad,confirmed,denied FROM request WHERE goodorbad=1 AND confirmed=0 AND denied=0 Order by ID ASC");
echo '
<!-- **********************************************************************************************************************************************************
MAIN CONTENT
*********************************************************************************************************************************************************** -->
<!--main content start-->
<section id="main-content">
<section class="wrapper site-min-height">
<h3><i class="fa fa-angle-right"></i> Non Authenticated Requests</h3>
<div class="row mt">
<div class="col-lg-12">
<p>Non Authenticated Requests here.</p>';
echo '<div class="row mt">
<div class="col-md-12">
<div class="content-panel">
<table class="table table-striped table-advance table-hover">
<h4><i class="fa fa-angle-right"></i>Non Authenticated Requests</h4>
<hr> <thead>
<tr>
<th><i class="fa fa-bullhorn"></i>Username</th>
<th><i class="fa fa-phone"></i>Phone number update request</th>
<th><i class="fa fa-bookmark"></i>Requester</th>
<th><i class=" fa fa-edit"></i> Status</th>
<th><i class=" fa fa-edit"></i> Accept/Decline</th>
<th></th>
</tr>
</thead>';
$i = 1;
while($row = $results->fetch_object())
{
//$row->id
//$row->confirmed
//$row->denied
$status = $row->confirmed;
echo '
<!-- Modal for Confirm -->
<form action="#" method="POST">
<div aria-hidden="true" aria-labelledby="myModalLabel" role="dialog" tabindex="-1" id="myModal'.$i.'" class="modal fade">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<input type="hidden" name="username_request" value="'.$row->username.'"/>
<input type="hidden" name="telephone_request" value="'.$row->phone.'"/>
<h4 class="modal-title">Are you sure ?</h4>
</div>
<div class="modal-body">
<br>
<p>You are about to update </p>
'.$row->username.'
<br>
<p> with the following telephone number </p>
'.$row->phone.'
<div class="modal-footer">
<button data-dismiss="modal" class="btn btn-default"
type="button">Cancel</button>
<button data-dismiss="modal" class="btn btn-default"
type="button">Submit</button>
</div>
</div>
</div>
</div>
</form>
<!-- modal -->
<tbody>
<tr>
<td>'.$row->username.'</td>
<td>'.$row->phone.'</td>
<td>'.$row->requester.' </td>';
if($status == 1)
{
echo ' <td><span class="label label-success">Completed</span></td>
<td></td>
<td></td>
';
}
echo '<td><span class="label label-info label-mini">Pending</span></td>
<td>
Accept?
<a data-toggle="modal" href="#myModal'.$i.'"> <button class="btn btn-success btn-xs"><i class="fa fa-check"></i></button>
</a>
<td>
Decline?
<button class="btn btn-danger btn-xs"><i class="fa fa-minus-circle"></i></button>
</td>
</td>
</tr>
</tbody>
';
$i++;
}
echo '
</table>
</div><!-- /content-panel -->
</div><!-- /col-md-12 -->
</div><!-- /row -->';
// close connection
$mysqli->close();
?>
<html>
</html>
You will have to change 2 lines. The reason of error is you are calling the same id again and again. So you will have to change id dynamically with loop. You will have to change your 2 lines like these:
<div aria-hidden="true" aria-labelledby="myModalLabel" role="dialog" tabindex="-1" id="myModal'.$i.'" class="modal fade">
and
<a data-toggle="modal" href="#myModal'.$i.'"> <button class="btn btn-success btn-xs"><i class="fa fa-check"></i></button></a>
Final code is:
<?php
require_once ("includes/session_check.php");
require_once ("includes/db_connect.php");
//MySqli Select Query
$results = $mysqli->query("SELECT id, username, phone, requester,goodorbad,confirmed,denied FROM request WHERE goodorbad=1 AND confirmed=0 AND denied=0 Order by ID ASC");
echo '
<!-- **********************************************************************************************************************************************************
MAIN CONTENT
*********************************************************************************************************************************************************** -->
<!--main content start-->
<section id="main-content">
<section class="wrapper site-min-height">
<h3><i class="fa fa-angle-right"></i> Non Authenticated Requests</h3>
<div class="row mt">
<div class="col-lg-12">
<p>Non Authenticated Requests here.</p>';
echo '<div class="row mt">
<div class="col-md-12">
<div class="content-panel">
<table class="table table-striped table-advance table-hover">
<h4><i class="fa fa-angle-right"></i>Non Authenticated Requests</h4>
<hr> <thead>
<tr>
<th><i class="fa fa-bullhorn"></i>Username</th>
<th><i class="fa fa-phone"></i>Phone number update request</th>
<th><i class="fa fa-bookmark"></i>Requester</th>
<th><i class=" fa fa-edit"></i> Status</th>
<th><i class=" fa fa-edit"></i> Accept/Decline</th>
<th></th>
</tr>
</thead>';
$i=0;
while($row = $results->fetch_object()) {
$i++;
//$row->id
//$row->confirmed
//$row->denied
$status = $row->confirmed;
echo '
<!-- Modal for Confirm -->
<form action="#" method="POST">
<div aria-hidden="true" aria-labelledby="myModalLabel" role="dialog" tabindex="-1" id="myModal'.$i.'" class="modal fade">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<input type="hidden" name="username_request" value="'.$row->username.'"/>
<input type="hidden" name="telephone_request" value="'.$row->phone.'"/>
<h4 class="modal-title">Are you sure ?</h4>
</div>
<div class="modal-body">
<br>
<p>You are about to update </p>
'.$row->username.'
<br>
<p> with the following telephone number </p>
'.$row->phone.'
<div class="modal-footer">
<button data-dismiss="modal" class="btn btn-default"
type="button">Cancel</button>
<button data-dismiss="modal" class="btn btn-default"
type="button">Submit</button>
</div>
</div>
</div>
</div>
</form>
<!-- modal -->
<tbody>
<tr>
<td>'.$row->username.'</td>
<td>'.$row->phone.'</td>
<td>'.$row->requester.' </td>';
if($status == 1){
echo ' <td><span class="label label-success">Completed</span></td>
<td></td>
<td></td>
';
}else{
}
echo '<td><span class="label label-info label-mini">Pending</span></td>
<td>
Accept?
<a data-toggle="modal" href="#myModal'.$i.'"> <button class="btn btn-success btn-xs"><i class="fa fa-check"></i></button>
</a>
<td>
Decline?
<button class="btn btn-danger btn-xs"><i class="fa fa-minus-circle"></i></button>
</td>
</td>
</tr>
</tbody>
';
}
echo '
</table>
</div><!-- /content-panel -->
</div><!-- /col-md-12 -->
</div><!-- /row -->';
// close connection
$mysqli->close();
?>
<html>
</html>