I am trying to build a budget lookup tool. I have form where someone enters an account#, fund#, and deptID#. When they hit search, it opens a modal and will display a table of the budget balances that match the entered fund, account, and deptID.
I can get the modal to open but, I can't seem to get the data to pass to the modal and display the data based on the SQL query. Here is my code:
Here is the form:
<form method="GET" id="frm" name="frm">
<div class="row">
<div class="col mb-2">
<label for="account">Account:</label>
<select class="form-control" name="account2" id="account2" required>
<option></option>
<?php
while(!$accounts->atEnd()) { //dyn select
?>
<option value="<?php echo($accounts->getColumnVal("account")); ?>"><?php echo($accounts->getColumnVal("account")); ?>: <?php echo($accounts->getColumnVal("description")); ?></option>
<?php
$accounts->moveNext();
} //dyn select
$accounts->moveFirst();
?>
</select>
</div>
<div class="col mb-2">
<label for="fund">Fund:</label>
<select class="form-control" name="fund2" id="fund2" required>
<option></option>
<?php
while(!$funds->atEnd()) { //dyn select
?>
<option value="<?php echo($funds->getColumnVal("fundID")); ?>"><?php echo($funds->getColumnVal("fundID")); ?>: <?php echo($funds->getColumnVal("fund")); ?></option>
<?php
$funds->moveNext();
} //dyn select
$funds->moveFirst();
?>
</select>
</div>
</div>
<div class="row">
<div class="col mb-2">
<label for="fund">Department ID#:</label>
<input type="text" name="funding_department2" id="funding_department2" class="form-control input-md" autocomplete="off" value="" required>
</div></div>
<button type="submit" name="submit2" id="submit2" class="btn-lg btn-info">Search</button>
</form>
Here is the script and modal:
<script>
$(document).ready(function() {
$('#frm').on('submit2', function(e){
$('#myLargeModalLabel').modal('show');
e.preventDefault();
});
});
</script>
<!-- Large modal -->
<div class="modal fade bd-example-modal-lg" tabindex="-1" id="myLargeModalLabel" role="dialog" aria-labelledby="myLargeModalLabel" aria-hidden="true">
<div class="modal-dialog modal-lg">
<div class="modal-content p-4">
<h4 class="modal-title">Budget Summary</h4>For Account: <?php echo $_GET['account2']; ?>, Fund: <?php echo $fund; ?>, DeptID#: <?php echo $deptID; ?><br><em>The budgeted balance is an estimate.</em></h4>
<br> <?php if ($budget_summary->TotalRows == 0) { // Show if mysqli recordset empty ?>There is no data. Please try your search again.<?php } ?>
<?php if ($budget_summary->TotalRows > 0) { // Show if mysqli recordset empty ?><table width="100%" class="table table-responsive" border="0" cellspacing="2" cellpadding="6" class="display" id="example2">
<thead>
<tr>
<th align="left" valign="top">Budgeted Amount</th>
<th align="left" valign="top">Budgeted Balance</th>
<th align="left" valign="top">Program</th>
</tr>
</thead>
<tbody>
<?php
while(!$budget_summary->atEnd()) {
?><tr>
<td valign="top">$<?php echo($budget_summary->getColumnVal("budgeted_amount")); ?></td>
<td valign="top">$<?php echo($budget_summary->getColumnVal("budgeted_balance")); ?></td>
<td valign="top"><?php echo($budget_summary->getColumnVal("program")); ?></td>
</tr>
<?php
$budget_summary->moveNext();
}
$budget_summary->moveFirst(); //return RS to first record
?>
</tbody>
</table><?php } ?>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
Here is the SQL query:
<?php
$fund = mysqli_real_escape_string($sa, $_GET["fund2"]);
$account = mysqli_real_escape_string($sa, $_GET["account2"]);
$deptID = mysqli_real_escape_string($sa, $_GET["funding_department2"]);
$budget_summary = new WA_MySQLi_RS("budget_summary",$sa,0);
$budget_summary->setQuery("SELECT * from budget_summary where fund = ? and account = ? and deptID = ?");
$budget_summary->bindParam("i", "".$fund ."", "-1"); //colname
$budget_summary->bindParam("i", "".$account ."", "-1"); //colname2
$budget_summary->bindParam("i", "".$funding_department ."", "-1"); //colname3
$budget_summary->execute();
?>
You have things out of sequence. The select/submit button should trigger a back-end operation to retrieve the data from the database (through an ajax request), which would then return the data to your page as JSON which you could parse in javascript into HTML- OR - instead of returning JSON data, you could return the HTML for your modal. Maybe something like this
$(document).ready(function() {
$('#frm').submit(function(e){
// gather your inputs
var url="backend-php.php";
$.ajax({
url: url, // your back-end PHP script, will return the HTML needed
method: 'GET',
data : {
account2: $('#account2').val(),
fund2: $('#fund2').val(),
funding_department2: $('#funding_department2').val(),
},
success: function(result){
$('#myLargeModalLabelHTML').html(result)
$('#myLargeModalLabel').modal('show');
}
})
e.preventDefault();
});
});
Your MOdal HTML could become:
<!-- Large modal -->
<div class="modal fade bd-example-modal-lg" tabindex="-1" id="myLargeModalLabel" role="dialog" aria-labelledby="myLargeModalLabel" aria-hidden="true">
<div class="modal-dialog modal-lg">
<div class="modal-content p-4" id="myLargeModalLabelHTML">
<!-- everything will go in here -->
</div>
<div class="modal-footer"><button type="button" class="btn btn-default" data-dismiss="modal">Close</button></div>
</div>
</div>
and your PHP script, something like:
<?php
function getModalHtml() {
$budget_summary = new WA_MySQLi_RS("budget_summary",$sa,0);
$budget_summary->setQuery("SELECT * from budget_summary where fund = ? and account = ? and deptID = ?");
$budget_summary->bindParam("i", $_GET["fund2"], "-1"); //colname
$budget_summary->bindParam("i", $_GET["account2"], "-1"); //colname2
$budget_summary->bindParam("i", $_GET["funding_department2"], "-1"); //colname3
$budget_summary->execute();
?>
<h4 class="modal-title">Budget Summary</h4>For Account: <?php echo $_GET['account2']; ?>, Fund: <?php echo $fund; ?>, DeptID#: <?php echo $deptID; ?><br><em>The budgeted balance is an estimate.</em></h4>
<br> <?php if ($budget_summary->TotalRows == 0) { // Show if mysqli recordset empty ?>There is no data. Please try your search again.<?php } ?>
<?php if ($budget_summary->TotalRows > 0) { // Show if mysqli recordset empty ?><table width="100%" class="table table-responsive" border="0" cellspacing="2" cellpadding="6" class="display" id="example2">
<thead>
<tr>
<th align="left" valign="top">Budgeted Amount</th>
<th align="left" valign="top">Budgeted Balance</th>
<th align="left" valign="top">Program</th>
</tr>
</thead>
<tbody>
<?php
while(!$budget_summary->atEnd()) {
?><tr>
<td valign="top">$<?php echo($budget_summary->getColumnVal("budgeted_amount")); ?></td>
<td valign="top">$<?php echo($budget_summary->getColumnVal("budgeted_balance")); ?></td>
<td valign="top"><?php echo($budget_summary->getColumnVal("program")); ?></td>
</tr>
<?php
$budget_summary->moveNext();
}
$budget_summary->moveFirst(); //return RS to first record
?>
</tbody>
</table><?php } ?>
<?php }?>
Related
So to sum up my problem and what I'm trying to do:
I'm trying to code an Attendance feature in my PHP Website where the admin first chooses the Class he wants to mark the Attendance for, and then he's taken to a new page with a table that ONLY displays students from THAT class. He enter the date/status of each student and presses Submit, and multiple rows are inserted into the "attendance" table.
Now, this was working perfectly before. The only new addition to this feature was the "Class" feature, now each student has a class (you might call it grade in your region). Before, they didn't.
So naturally, the table's SELECT query went from
$rows2 = $conn->query("SELECT * FROM students")->fetchAll(PDO::FETCH_ASSOC);
to:
$rows2 = $conn->query("SELECT * FROM students WHERE grade_id = $grade")->fetchAll(PDO::FETCH_ASSOC);
This little addition has completely messed up my INSERT query, which works fine when I exclude the "WHERE" clause. Below, I'm attaching code for two pages - one is ChooseClass.php where admin picks the Class he wants to add Attendance for. This page basically sends the chosen class ID to the 2nd page, which is AddAttendance.php.
ChooseClass.php:
<?php include('../db.php');
session_start();
$email = $_SESSION["email"];
$user = $conn->query("SELECT * from admin where email = '$email' ")->fetchAll(PDO::FETCH_ASSOC);
$userID = $user[0]['admin_id'];
$someotherRow = $conn->query("SELECT * FROM grade")->fetchAll(PDO::FETCH_ASSOC);
?>
<!DOCTYPE html>
<html>
<?php include('adminheader.php'); ?>
<body style="background-color: #5e72e4 !important;">
<!-- Sidenav -->
<?php include('adminsidebar.php'); ?>
<div class="main-content" id="panel">
<!-- Topnav -->
<?php include('admintopbar.php'); ?>
<!-- Header -->
<!-- Header -->
<div class="header bg-primary pb-6" style="background-color: #5e72e4 !important;">
<div class="container-fluid">
<div class="header-body">
<div class="row align-items-center py-4">
<div class="col-lg-6 col-7">
<h6 class="h2 text-white d-inline-block mb-0">Attendance Managament</h6>
</div>
</div>
<!-- Card stats -->
<div class="row">
<div class="col-lg-12">
<div class="card">
<!-- Card body -->
<div class="card-header">Choose a Class</div>
<div class="card-body">
<div class="table-responsive" style="overflow-y: scroll; height: 600px;">
<table class="table align-items-center table-dark table-flush">
<thead class="thead-dark">
<tr>
<th scope="col" class="sort" data-sort="name">Class Name</th>
<th scope="col" class="sort" data-sort="status">Action</th>
</tr>
</thead>
<tbody class="list">
<?php
foreach ($someotherRow as $row) { ?>
<tr>
<th scope="row">
<div class="media align-items-center">
<div class="media-body">
<span class="name mb-0 text-sm"><?php echo $row['grade_name']; ?></span>
</div>
</div>
</th>
<td>
<form action="" method="POST">
<a type="submit" href="adminmarkattendance.php?gradeid=<?php echo $row['grade_id']; ?> " class="btn btn-primary">Select</a>
</form>
</td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- Page content -->
<div class="container-fluid mt--6">
<!-- background-color: #5e72e4 !important; height: 63.9vh; -->
</div>
</div>
</body>
</html>
AddAttendance.php:
<?php include('../db.php');
session_start();
$email = $_SESSION["email"];
$user = $conn->query("SELECT * from admin where email = '$email' ")->fetchAll(PDO::FETCH_ASSOC);
$userID = $user[0]['admin_id'];
$grade = 0;
if (isset($_GET['gradeid'])) {
$grade = $_GET['gradeid'];
}
$rows2 = $conn->query("SELECT * FROM students WHERE grade_id = $grade")->fetchAll(PDO::FETCH_ASSOC);
$count = count($rows2);
if (isset($_POST["submit"])) {
for ($i = 0; $i < $count; $i++) {
$student_id = $_POST["id"][$i];
$status = $_POST['options'][$i];
$grade_id = $_POST['grade_id'];
$date = $_POST['attendancedate'];
$date = date('Y-m-d', strtotime($date));
$queryInsert = $conn->prepare("INSERT
into attendance
(
student_id,
grade_id,
date,
status
)
values
(
$student_id,
$grade_id,
'$date',
'$status'
)
");
$queryInsert->execute();
}
echo "<script> location.replace('chooseclass.php'); </script>";
}
?>
<!DOCTYPE html>
<html>
<?php include('adminheader.php'); ?>
<body style="background-color: #5e72e4 !important;">
<!-- Sidenav -->
<?php include('adminsidebar.php'); ?>
<div class="main-content" id="panel">
<!-- Topnav -->
<?php include('admintopbar.php'); ?>
<!-- Header -->
<!-- Header -->
<div class="header bg-primary pb-6" style="background-color: #5e72e4 !important;">
<div class="container-fluid">
<div class="header-body">
<div class="row align-items-center py-4">
<div class="col-lg-6 col-7">
<h6 class="h2 text-white d-inline-block mb-0">Mark Attendance</h6>
</div>
</div>
<!-- Card stats -->
<div class="row">
<div class="col-lg-12">
<form action="adminmarkattendance.php" method="post">
<div class="row">
<div class="col">
<div class="card bg-default shadow">
<div class="card-header bg-transparent border-0">
<div class="form-inline">
<div class="col-lg-6">
<h3 class="text-white mb-0">Registered Students</h3>
</div>
<div class="col-lg-6">
<div class="form-group">
<input style="width: 100%;" class="form-control" name="attendancedate" type="date" required>
</div>
</div>
</div>
</div>
<div class="table-responsive" style="overflow-y: scroll; height: 600px;">
<table class="table align-items-center table-dark table-flush">
<thead class="thead-dark">
<tr>
<th scope="col" class="sort" data-sort="name">Avatar</th>
<th scope="col" class="sort" data-sort="name">Student Name</th>
<th scope="col" class="sort" data-sort="status">Phone Number</th>
<th scope="col" class="sort" data-sort="status">Age</th>
<th scope="col" class="sort" data-sort="status">Gender</th>
<th scope="col" class="sort" data-sort="status">Address</th>
<th scope="col" class="sort" data-sort="status">Action</th>
</tr>
</thead>
<tbody class="list">
<?php
foreach ($rows2 as $row) { ?>
<tr>
<td>
<img src="<?php echo '../profileImages/' . $row['profile_image'] ?>" width="45" height="45" alt="">
<input type="hidden" name="id[]" value="<?php echo $row['student_id']; ?>">
<input type="hidden" name="grade_id" value="<?php echo $grade ?>">
</td>
<th scope="row">
<div class="media align-items-center">
<div class="media-body">
<span class="name mb-0 text-sm"><?php echo $row['fname'] . ' ' . $row['lname']; ?></span>
</div>
</div>
</th>
<td>
<span class="badge badge-dot mr-4">
<span class="status"><?php echo $row['phonenumber']; ?></span>
</span>
</td>
<td>
<span class="badge badge-dot mr-4">
<span class="status"><?php echo $row['age']; ?></span>
</span>
</td>
<td>
<span class="badge badge-dot mr-4">
<span class="status"><?php echo $row['gender']; ?></span>
</span>
</td>
<td>
<span class="badge badge-dot mr-4">
<span class="status"><?php echo $row['address']; ?></span>
</span>
</td>
<td>
<select class="form-control" name="options[]">
<option value="Present" selected>Present</option>
<option value="Absent">Absent</option>
</select>
</td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
</div>
</div>
</div>
<div class="text-center">
<button type="submit" name="submit" style="width: 100%;" class="btn btn-warning">Mark Attendance</button>
</div>
</form>
</div>
</div>
</div>
</div>
<!-- Page content -->
<div class="container-fluid mt--6">
<!-- background-color: #5e72e4 !important; height: 63.9vh; -->
</div>
</div>
</body>
</html>
I've spent 2 hours looking at this code and I can't figure out why the addition of WHERE breaks my code. I've also var_dumped most of the variables, just to check if I was entering some NULL value and I'm not. So kindly look into it and see if you can figure out why data is not being inserted into the database..
You are sending gradeid value in -
href="adminmarkattendance.php?gradeid= "
And getting value in AddAttendance.php
So, first give right path and second, there is also a space within ahref. So, when you try to get the value use trim, it will remove spaces -
$grade = trim($_GET['gradeid']);
I have a form that asks for 3 fields. Once the form is submitted, it should open a modal. In the modal a budget summary should show. The budget summary data is pulled from a database and the values are based on the 3 form fields entered. I can't seem to get the values to show up in the modal so the query will work but, the modal does open.
Here is the modal code:
<!-- Large modal -->
<div class="modal fade bd-example-modal-lg" tabindex="-1" id="myLargeModalLabel" role="dialog" aria-labelledby="myLargeModalLabel" aria-hidden="true">
<div class="modal-dialog modal-lg">
<div class="modal-content p-4">
<h4 class="modal-title">Budget Summary</h4>For Account: <?php echo $account; ?>, Fund: <?php echo $_POST['fund2']; ?>, DeptID#: <?php echo $deptID; ?><br><em>The budgeted balance is an estimate.</em></h4>
<br> <?php if ($budget_summary->TotalRows == 0) { // Show if mysqli recordset empty ?>There is no data. Please try your search again.<?php } ?>
<?php if ($budget_summary->TotalRows > 0) { // Show if mysqli recordset empty ?><table width="100%" class="table table-responsive" border="0" cellspacing="2" cellpadding="6" class="display" id="example2">
<thead>
<tr>
<th align="left" valign="top">Budgeted Amount</th>
<th align="left" valign="top">Budgeted Balance</th>
<th align="left" valign="top">Program</th>
</tr>
</thead>
<tbody>
<?php
while(!$budget_summary->atEnd()) {
?><tr>
<td valign="top">$<?php echo($budget_summary->getColumnVal("budgeted_amount")); ?></td>
<td valign="top">$<?php echo($budget_summary->getColumnVal("budgeted_balance")); ?></td>
<td valign="top"><?php echo($budget_summary->getColumnVal("program")); ?></td>
</tr>
<?php
$budget_summary->moveNext();
}
$budget_summary->moveFirst(); //return RS to first record
?>
</tbody>
</table><?php } ?>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
Here is the sql query:
<?php
$budget_summary = new WA_MySQLi_RS("budget_summary",$sa,0);
$budget_summary->setQuery("SELECT * from budget_summary where fund = ? and account = ? and deptID = ?");
$budget_summary->bindParam("i", "".$_POST['fund '] ."", "-1"); //colname
$budget_summary->bindParam("i", "".$_POST['account'] ."", "-1"); //colname2
$budget_summary->bindParam("i", "".$_POST['funding_department'] ."", "-1"); //colname3
$budget_summary->execute();
?>
Here is the form:
<form method="POST" id="frm" name="frm">
<div class="row">
<div class="col mb-2">
<label for="account">Account:</label>
<select class="form-control" name="account2" id="account2" required>
<option></option>
<?php
while(!$accounts->atEnd()) { //dyn select
?>
<option value="<?php echo($accounts->getColumnVal("account")); ?>"><?php echo($accounts->getColumnVal("account")); ?>: <?php echo($accounts->getColumnVal("description")); ?></option>
<?php
$accounts->moveNext();
} //dyn select
$accounts->moveFirst();
?>
</select>
</div>
<div class="col mb-2">
<label for="fund">Fund:</label>
<select class="form-control" name="fund2" id="fund2" required>
<option></option>
<?php
while(!$funds->atEnd()) { //dyn select
?>
<option value="<?php echo($funds->getColumnVal("fundID")); ?>"><?php echo($funds->getColumnVal("fundID")); ?>: <?php echo($funds->getColumnVal("fund")); ?></option>
<?php
$funds->moveNext();
} //dyn select
$funds->moveFirst();
?>
</select>
</div>
</div>
<div class="row">
<div class="col mb-2">
<label for="fund">Department ID#:</label>
<input type="text" name="funding_department2" id="funding_department2" class="form-control input-md" autocomplete="off" value="" required>
</div></div>
<button type="submit" name="submit2" id="submit2" class="btn-lg btn-info">Search</button>
</form>
<script>
$(document).ready(function() {
$('#frm').on('submit', function(e){
$('#myLargeModalLabel').modal('show');
e.preventDefault();
});
});
</script>
Any tips would be appreciated on how to make this happen. I have been trying for days to figure it out. Thank you.
Do you insert the data directly into the databse or into fields in your modal?
Try the following:
Insert Data into the fields (if you have them), than try to print them with either PHP or Java to see if you recieve any values.
If you recieve them with java and can print them with java:
Your client gets the data that you insert but PHP is the serverside of you programm. You need to get the data with a php-statement.
Goal:
If I click on a td a jQuery AJAX request is made which sends the correct reservationid through a POST request to the same page where the td is. In the PHP file I want to invoke a query and get information about the reservation with the id which was sent through POST. After that it opens a Bootstrap modal where it shows reservation details about the clicked reservation.
Problem:
In the network sight i can see that a POST request is fired and it sends reservationid. But I can't use the $_POST['reservationid'], PHP says there is no value in it. If i try to use var_dump($_POST) then there is also no value inside of it.
if ($(this).hasClass("reserved") || $(this).hasClass("reserved-right")) {
var reservationid = $(this).attr('data-id');
$.ajax({
type: 'POST',
url: 'http://localhost/platzverwaltungssystemprotoyp/app/Views/reservierung/platzverwaltung.php',
data: {
'reservationid': reservationid
},
success: function() {
$('#abfragereservierung').find('#reservationid').val(reservationid);
$("#abfragereservierung").modal("show");
}
});
<td class="reserved" data-id="'. $counter['1']->reservationid .'"></td>
<td class="reserved" data-id="'. $counter['2']->reservationid .'"></td>
<td class="reserved" data-id="'. $counter['3']->reservationid .'"></td>
<?php
include "modals/abfragereservierung.php"
?>
abfragereservierung.php:
<?php
$reservationIdFromTd = isset($_POST['reservationid']) ? $_POST['reservationid'] : null;
if ($reservationIdFromTd != null) {
$reservierungFromId = $resController->getReservierungFromId($reservationIdFromTd);
}
?>
<form method="post">
<div class="modal fade" id="abfragereservierung" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Reservierung Nr.
<?php echo $reservierungFromId->reservationid ?>
</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<h6>Daten</h6>
<div id="reservationdata">
<table class="table table-hover">
<tbody>
<input type="text" name="reservationid" id="reservationid">
<tr>
<th>Name</th>
<td>
<p>
<?php echo $_POST['reservationid']; ?>
</p>
</td>
</tr>
<tr>
<th>Platz</th>
<td>
<p>
<?php echo $reservierungFromId->tenniscourts_tenniscourtid ?>
</p>
</td>
</tr>
<tr>
<th>Datum</th>
<td>
<p>
<?php echo $reservierungFromId->reservierung_am ?>
</p>
</td>
</tr>
<tr>
<th>Uhrzeit von</th>
<td>
<p>
<?php echo $reservierungFromId->reservierungsanfang ?>
</p>
</td>
</tr>
<tr>
<th>Uhrzeit bis</th>
<td>
<p>
<?php echo $reservierungFromId->reservierungsende ?>
</p>
</td>
</tr>
<tr>
<th>Bemerkung</th>
<td>
<p>
<?php echo $reservierungFromId->bemerkung ?>
</p>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-danger" data-dismiss="modal">Abbrechen</button>
<button class="btn btn-warning" type="submit" name="submit" id="submit" value="submit">Reservierung stornieren</button>
</div>
</div>
</div>
</div>
</form>
In HTML:
<td class="reserved" data-id="'. $counter['1']->reservationid .'"></td>
<td class="reserved" data-id="'. $counter['2']->reservationid .'"></td>
<td class="reserved" data-id="'. $counter['3']->reservationid .'"></td>
<script>
if($(this).hasClass("reserved") || $(this).hasClass("reserved-right")){
var reservationid = $(this).attr('data-id');
$.ajax({
type: 'POST',
url: 'http://localhost/platzverwaltungssystemprotoyp/app/Views/reservierung/platzverwaltung.php',
data: {
'reservationid': reservationid
},
success: function (){
$('#abfragereservierung').find('#reservationid').val( reservationid );
$("#abfragereservierung").modal("show");
}
});
</script>
In abfragereservierung.php:
<?php
$reservationIdFromTd = isset($_POST['reservationid']) ? $_POST['reservationid'] : null;
if($reservationIdFromTd != null){
$reservierungFromId = $resController->getReservierungFromId($reservationIdFromTd);
}
?>
<form method="post">
<div class="modal fade" id="abfragereservierung" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Reservierung Nr. <?php echo $reservierungFromId->reservationid ?></h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<h6>Daten</h6>
<div id="reservationdata">
<table class="table table-hover">
<tbody>
<input type="text" name="reservationid" id="reservationid">
<tr>
<th>Name</th>
<td><p><?php echo $_POST['reservationid']; ?></p></td>
</tr>
<tr>
<th>Platz</th>
<td><p><?php echo $reservierungFromId->tenniscourts_tenniscourtid ?></p></td>
</tr>
<tr>
<th>Datum</th>
<td><p><?php echo $reservierungFromId->reservierung_am ?></p></td>
</tr>
<tr>
<th>Uhrzeit von</th>
<td><p><?php echo $reservierungFromId->reservierungsanfang ?></p></td>
</tr>
<tr>
<th>Uhrzeit bis</th>
<td><p><?php echo $reservierungFromId->reservierungsende ?></p></td>
</tr>
<tr>
<th>Bemerkung</th>
<td><p><?php echo $reservierungFromId->bemerkung ?></p></td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-danger" data-dismiss="modal">Abbrechen</button>
<button class="btn btn-warning" type="submit" name="submit" id="submit" value="submit">Reservierung stornieren</button>
</div>
</div>
</div>
</div>
</form>
Don't include PHP to HTML, because it PHP load, it will load modal, it should load in Ajax
After I successfully edited data using PHP ajax and MySQLi, the
“<input type="text" class="tagsinput"/>” is not properly initialized.
I try this code, and it works but not in its proper form
$(document).ajaxComplete(function () {
$(document).find('.tagsinput').tagsInput();
});
This is the picture of not yet submitted form
This is the picture of successfully edited data, but I want to edit
again
This is my ajax call code
$(document).on('click', '.edit_fp_follow_up', function () {
$fp_follow_up_id = $(this).val();
$method = $('#method' + $fp_follow_up_id).val();
if (confirm('Are you sure you want to edit this follow-up?')) {
$.ajax({
type: "POST",
url: "action/editfpfollowup.php",
cache: false,
async: false,
data: {
fp_follow_up_id: $fp_follow_up_id,
method: $method,
edit: 1,
},
success: function () {
$('#alert').slideDown();
$('#alerttext').text('Successfully updated Follow-up Schedule!');
setTimeout(function () {
$('#alert').fadeOut('slow');
}, 1500);
$(document).ajaxComplete(function () {
$(document).find('.tagsinput').tagsInput();
});
show_follow_up_familyplanning();
}
});
}
});
This is my modal code
<div class="modal fade" id="edit_fp_follow_up<?php echo $fetch1['fp_follow_up_id']; ?>" tabindex="-1" role="dialog" aria-labelledby="defModalHead" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<center>
<div id="modallabel2" class="alert alert-danger" style="display:none;">
<center><span id="checkfield2"></span></center>
</div>
</center>
<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="defModalHead"><strong>Update Follow-up Visit - Family Planning</strong></h4>
</div>
<div class="modal-body">
<form id="fpfollowup">
<fieldset>
<div class="col-md-12">
<div class="form-group">
<label>Method/Brand</label>
<input type="text" class="tagsinput" id="method<?php echo $fetch1['fp_follow_up_id']; ?>" value="<?php echo $fetch1['method_brand']; ?>" data-role="tagsinput" required />
</div>
</fieldset>
</form>
</div>
<div class="modal-footer">
<button type="button" value="<?php echo $fetch1['fp_follow_up_id']; ?>" class="btn btn-success edit_fp_follow_up">Save</button>
<button type="button" class="btn btn-danger" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
This is my code in my table
<div class="table-responsive">
<table id="fpfollowuptable" class="table datatable hover">
<thead>
<tr class="warning">
<th>
<center>Patient ID</center>
</th>
<th>
<center>Patient Name</center>
</th>
<th>
<center>Remarks</center>
</th>
<th>
<center>Next Service Date</center>
</th>
<th>
<center>Status</center>
</th>
<th>
<center>Actions</center>
</th>
</tr>
</thead>
<tbody>
<?php
require '../require/config.php';
$query1 = $conn->query("SELECT * FROM `fp_follow_up` NATURAL JOIN `patient` WHERE `fp_follow_up`.`patient_id` = `patient`.`patient_id` ORDER BY `fp_follow_up_id` DESC") or die(mysqli_error());
while($fetch1 = $query1->fetch_array()){
?>
<tr>
<td>
<center><strong><?php echo $fetch1['year']?><?php echo "0".$fetch1['patient_id']?></strong></center>
</td>
<td>
<center><strong><?php echo $fetch1['patient_name']?></strong></center>
</td>
<td>
<center><?php echo $fetch1['remarks']?></center>
</td>
<td>
<center><?php echo $fetch1['next_service_date']?></center>
</td>
<td>
<center>
<?php
if ($fetch1['follow_up_status'] == 'Pending')echo "<span class='badge badge-danger animated infinite pulse' style='animation-duration:.8s;'>Pending</span>";
if ($fetch1['follow_up_status'] == 'Done')echo "<span class='badge badge-info'>Done</span>";
if ($fetch1['follow_up_status'] == 'Cancelled')echo "<span class='badge badge-warning'>Cancelled</span>";
?></center>
</td>
<td>
<center><button class="btn btn-sm btn-info" data-toggle="modal" data-target="#edit_fp_follow_up<?php echo $fetch1['fp_follow_up_id']; ?>">UPDATE</button></center>
</td>
<?php require('../modals/edit_fp_follow_up.php'); ?>
</tr>
<?php
}
$conn->close();
?>
</tbody>
</table>
</div>
Have you tried using
<input type="text" class="tagsinput" data-role="tagsinput"/>
Demo Here: https://codepen.io/dannibla/pen/QGLyBW
Just add data-role="tagsinput" to your input field to automatically
change it to a tags input field.
You have created modals in loops..
<input type="text" class="tagsinput<?php echo $fetch1['fp_follow_up_id']; ?>" id="method<?php echo $fetch1['fp_follow_up_id']; ?>" value="<?php echo $fetch1['method_brand']; ?>" data-role="tagsinput" required />
and then in jquery, try
$(document).find('.tagsinput'+fp_follow_up_id).tagsInput();
I'm have a page where I can view the purchase history of sales
When I click on view full details this is what I get
The problem is when I click print full details this is what I get, I only want to print the window that pops up when I click on view full details
How do I print only the View Full Details window part?
Here's my code:
<!-- History -->
<div class="modal fade" id="detail<?php echo $hrow['salesid']; ?>" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<center><h4 class="modal-title" id="myModalLabel">Purchase Full Details</h4></center>
</div>
<div class="modal-body">
<?php
$sales=mysqli_query($conn,"select * from sales where salesid='".$hrow['salesid']."'");
$srow=mysqli_fetch_array($sales);
?>
<div class="container-fluid">
<div class="row">x
<div class="col-lg-12">
<p class="pull-right">Date: <?php echo date("F d, Y", strtotime($srow['sales_date'])); ?></p>
</div>
</div>
<div class="row">
<div class="col-lg-12">
<label>
<button onclick="printsales()">Print Full details</button>
<script>
function printsales() {
window.print();
}
</script>
</label>
<table width="100%" class="table table-striped table-bordered table-hover">
<thead>
<tr>
<th>Product Name</th>
<th>Price</th>
<th>Purchase Qty</th>
<th>SubTotal</th>
</tr>
</thead>
<tbody>
<?php
$total=0;
$pd=mysqli_query($conn,"select * from sales_detail left join product on product.productid=sales_detail.productid where salesid='".$hrow['salesid']."'");
while($pdrow=mysqli_fetch_array($pd)){
?>
<tr>
<td><?php echo ucwords($pdrow['product_name']); ?></td>
<td align="right"><?php echo number_format($pdrow['product_price'],2); ?></td>
<td><?php echo $pdrow['sales_qty']; ?></td>
<td align="right">
<?php
$subtotal=$pdrow['product_price']*$pdrow['sales_qty'];
echo number_format($subtotal,2);
$total+=$subtotal;
?>
</td>
</tr>
<?php
}
?>
<tr>
<td align="right" colspan="3"><strong>Total</strong></td>
<td align="right"><strong><?php echo number_format($total,2); ?></strong></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal"><i class="fa fa-times"></i> Close</button>
</div>
</div>
</div>
</div>
You just need to insert simple javascript code to print whole page. And by clicking on Click here to Print you can get print window.
<script type="text/javascript">
function PrintElem(elem,title)
{
Popup($(elem).html(),title);
}
function Popup(data,title)
{
var mywindow = window.open('', '_blank','width=1000,height=700');
mywindow.document.write('<html><head><title>'+title+'</title></head>');
mywindow.document.write('<body onload="window.print()">');
mywindow.document.write(data);
mywindow.document.write('</body></html>');
mywindow.document.close();
return true;
}
</script>
Click here to Print
Add an ID to elements you want to hide, for example:
<div id="dontprint"> This will be hidden on print mode </div>
<div> This will be shown on print mode </div>
Then, using CSS hide those elements you don't want to print. Adding a code like this at the end of your code.
<style>
#media print {
div#dontprint{
display: none;
}
}
</style>