How to add value in html table column - javascript

I am working on the following codes. I need to add all the values per category in my table. The data is from the database. Please see the picture first:
Here is my interface image
Here is my HTML codes:
<table id="data" class="table table-bordered table-striped">
<thead>
<tr align="center">
<th width="5%">Item</th>
<th width="30%">Description</th>
<th width="5%">Unit</th>
<th width="5%">Qty</th>
<th width="10%">Unit Cost</th>
<th width="15%">Amount</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td colspan="5"><i>General Requirement</i></td>
</tr>
<?php
$id = $_GET['id'];
$select_bill = "SELECT *, quantity * unit_cost AS amount FROM bill_tbl WHERE project_name = $id";
$select_bill_result = mysqli_query($con,$select_bill);
if (mysqli_num_rows($select_bill_result)> 0) {
while ($row = mysqli_fetch_assoc($select_bill_result)) {
if ($row['category'] == 'General Requirement') {
?>
<tr>
<td></td>
<td><?php echo $row['description']; ?></td>
<td><?php echo $row['unit']; ?></td>
<td><?php echo $row['quantity']; ?></td>
<td><?php echo $row['unit_cost']; ?></td>
<td><?php echo $row['amount']; ?></td>
</tr>
<?php
}
}
}
?>
<tr>
<td></td>
<td colspan="4"><b>Subtotal</b></td>
<td></td>
</tr>
<tr>
<td>2</td>
<td colspan="5"><i>Concrete and Masonry Works</i></td>
</tr>
<?php
$id = $_GET['id'];
$select_bill = "SELECT *, quantity * unit_cost AS amount FROM bill_tbl WHERE project_name = $id";
$select_bill_result = mysqli_query($con,$select_bill);
if (mysqli_num_rows($select_bill_result)> 0) {
while ($row = mysqli_fetch_assoc($select_bill_result)) {
if ($row['category'] == 'Concrete and Masonry Works') {
?>
<tr>
<td></td>
<td><?php echo $row['description']; ?></td>
<td><?php echo $row['unit']; ?></td>
<td><?php echo $row['quantity']; ?></td>
<td><?php echo $row['unit_cost']; ?></td>
<td><?php echo $row['amount']; ?></td>
</tr>
<?php
}
}
}
?>
<tr>
<td></td>
<td colspan="4"><b>Subtotal</b></td>
<td></td>
</tr>
</tbody>
</table>
Script code
<script>
var total = 0;
var rows = $("#data tr:gt(0)");
rows.children("td:nth-child(6)").each(function() {
total += parseInt($(this).html());
});
$("#total").html(total);
</script>
This is for my school project.

You can sum it at PHP part. Code like this will sum all amounts while retrieving from DB.
<table id="data" class="table table-bordered table-striped">
<thead>
<tr align="center">
<th width="5%">Item</th>
<th width="30%">Description</th>
<th width="5%">Unit</th>
<th width="5%">Qty</th>
<th width="10%">Unit Cost</th>
<th width="15%">Amount</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td colspan="5"><i>General Requirement</i></td>
</tr>
<?php
$id = $_GET['id'];
$select_bill = "SELECT *, quantity * unit_cost AS amount FROM bill_tbl WHERE project_name = $id";
$select_bill_result = mysqli_query($con,$select_bill);
if (mysqli_num_rows($select_bill_result)> 0) {
while ($row = mysqli_fetch_assoc($select_bill_result)) {
if ($row['category'] == 'General Requirement') {
$subtotal += $row['amount']; //Here you sum all amounts from rows
?>
<tr>
<td></td>
<td><?php echo $row['description']; ?></td>
<td><?php echo $row['unit']; ?></td>
<td><?php echo $row['quantity']; ?></td>
<td><?php echo $row['unit_cost']; ?></td>
<td><?php echo $row['amount']; ?></td>
</tr>
<?php
}
}
}
?>
<tr>
<td></td>
<td colspan="4"><b>Subtotal</b></td>
<td><?php echo $subtotal; //Here you display subtotal ?></td>
</tr>
<tr>
<td>2</td>
<td colspan="5"><i>Concrete and Masonry Works</i></td>
</tr>
<?php
$id = $_GET['id'];
$select_bill = "SELECT *, quantity * unit_cost AS amount FROM bill_tbl WHERE project_name = $id";
$select_bill_result = mysqli_query($con,$select_bill);
if (mysqli_num_rows($select_bill_result)> 0) {
while ($row = mysqli_fetch_assoc($select_bill_result)) {
if ($row['category'] == 'Concrete and Masonry Works') {
$subtotal += $row['amount']; //Here you sum all amounts from rows
?>
<tr>
<td></td>
<td><?php echo $row['description']; ?></td>
<td><?php echo $row['unit']; ?></td>
<td><?php echo $row['quantity']; ?></td>
<td><?php echo $row['unit_cost']; ?></td>
<td><?php echo $row['amount']; ?></td>
</tr>
<?php
}
}
}
?>
<tr>
<td></td>
<td colspan="4"><b>Subtotal</b></td>
<td><?php echo $subtotal; //Here you display subtotal ?></td>
</tr>
</tbody>
</table>

<table id="data" class="table table-bordered table-striped">
<thead>
<tr align="center">
<th width="5%">Item</th>
<th width="30%">Description</th>
<th width="5%">Unit</th>
<th width="5%">Qty</th>
<th width="10%">Unit Cost</th>
<th width="15%">Amount</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td colspan="5"><i>General Requirement</i></td>
</tr>
<?php
$id = $_GET['id']; $catA =0; //this variable will be use to get the some of the category. You can name the variable whatever name you want
$select_bill = "SELECT *, quantity * unit_cost AS amount FROM bill_tbl WHERE project_name = $id";
$select_bill_result = mysqli_query($con,$select_bill);
if (mysqli_num_rows($select_bill_result)> 0) {
while ($row = mysqli_fetch_assoc($select_bill_result)) {
if ($row['category'] == 'General Requirement') {
$catA+=$row['amount']; // this will add each amount value to the $catA variable until the loop finished;
?>
<tr>
<td></td>
<td><?php echo $row['description']; ?></td>
<td><?php echo $row['unit']; ?></td>
<td><?php echo $row['quantity']; ?></td>
<td><?php echo $row['unit_cost']; ?></td>
<td><?php echo $row['amount']; ?></td>
</tr>
<?php
}
}
}
?>
<tr>
<td></td>
<td colspan="4"><b>Subtotal</b></td>
<td><?php echo $catA; //the variable now has the total sum of the amount;?></td>
</tr>
<tr>
<td>2</td>
<td colspan="5"><i>Concrete and Masonry Works</i></td>
</tr>
<?php
$id = $_GET['id']; $catB =0; //this variable will be use to get the some of the category. You can name the variable whatever name you want
$select_bill = "SELECT *, quantity * unit_cost AS amount FROM bill_tbl WHERE project_name = $id";
$select_bill_result = mysqli_query($con,$select_bill);
if (mysqli_num_rows($select_bill_result)> 0) {
while ($row = mysqli_fetch_assoc($select_bill_result)) {
if ($row['category'] == 'Concrete and Masonry Works') {
$catB+=$row['amount']; // this will add the amount value to the $catB variable until the loop finished;
?>
<tr>
<td></td>
<td><?php echo $row['description']; ?></td>
<td><?php echo $row['unit']; ?></td>
<td><?php echo $row['quantity']; ?></td>
<td><?php echo $row['unit_cost']; ?></td>
<td><?php echo $row['amount']; ?></td>
</tr>
<?php
}
}
}
?>
<tr>
<td></td>
<td colspan="4"><b>Subtotal</b></td>
<td><?php echo $catB; //the variable now has the total sum of the amount;?></td>
</tr>
</tbody>
</table>

Related

jquery or php if X is greater than Y

I'm making a website that displays a basic crud that shows Companyname, Stock, Minumum, Maximum.
I would like to display an alert or a message somewhere if the Stock is greater than the maximum. How could I go about doing this? Here is my display page code.
<table class="table">
<thead>
<tr>
<th>ID</th>
<th>Company Name</th>
<th>Stock</th>
<th>Minumum</th>
<th>Maximum</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php
if ($result->num_rows > 0) {
while ($row = $result->fetch_assoc()) {
?>
<tr>
<td><?php echo $row['id']; ?></td>
<td><?php echo $row['companyname']; ?></td>
<td><?php echo $row['stock']; ?></td>
<td><?php echo $row['minumum']; ?></td>
<td><?php echo $row['maximum']; ?></td>
<td><a class="btn btn-info" href="update1.php?id=<?php echo $row['id']; ?>">Edit</a> <a class="btn btn-danger" href="delete1.php?id=<?php echo $row['id']; ?>">Delete</a></td>
</tr>
You can put an additional message in the Stock column with an if statement.
<td><?php echo $row['stock']; ?></td>
with
<td><?php echo $row['stock']; if ($row['stock'] > $row['maximum']) { echo " > maximum"; } ?></td>

How to change each html table row accordian

I want to create a dynamic table which gets its all its entries coming from database. I know how to make a simple table accordian by this Twitter Bootstrap Use collapse.js on table cells [Almost Done] .
If I apply that technique it turns table rows into accordian but no matter which row i click it only expands first row.
Here is the code of my table getting data from database.
<div class="container">
<h2>All the Suggestions of HR</h2>
<div class="table-responsive">
<table id="myTable" width="100%" class="table table-striped display responsive nowrap table-hover">
<thead>
<tr>
<th scope="col">Status</th>
<th scope="col">Date</th>
<th scope="col">Time</th>
<th scope="col">Subject</th>
<th scope="col">Message</th>
<th scope="col">department</th>
<th scope="col">Actions</th>
</tr>
</thead>
<tbody>
<?php
$sql = "SELECT * FROM hr;";
$result = mysqli_query($conn , $sql);
$nr = mysqli_num_rows($result);
while($row = mysqli_fetch_assoc($result)) :
$id = $row['hr_id'];
?>
<tr>
<?php $timestamp = $row['timeSent'];
$date = date('d-m-Y',strtotime($timestamp));
$time = date('H:i:s',strtotime($timestamp));
$status = $row['isAnswered'];
?>
<td><?php if ($status == 'true') {
echo "Answerd";
}
else{
echo "Pending";
} ?></td>
<td><?php echo $date;?></td>
<td><?php echo $time;?></td>
<td><?php echo $row['subject'];?></td>
<td><?php echo $row['message'];?></td>
<td><?php
$cat = $row['category_id'];
if($cat == 1){
echo "Suggestion";
}
elseif ($cat == 2) {
echo "Claim";
}
else{
echo "Help";
}?></td>
</tr>
<?php endwhile; ?>
</tbody>
</table>
</div>
Whenever a row is clicked there is a content i want to show which is different for every row.
<?php
while($row = mysqli_fetch_assoc($result)) :
$id = $row['hr_id'];
?>
<tr data-toggle="collapse" data-target="#accordian_<?php echo $id; ?>" class="accordion-toggle">
<?php $timestamp = $row['timeSent'];
$date = date('d-m-Y',strtotime($timestamp));
$time = date('H:i:s',strtotime($timestamp));
$status = $row['isAnswered'];
?>
<td><?php echo $status == 'true' ? 'Answerd' : 'Pending'; ?></td>
<td><?php echo $date;?></td>
<td><?php echo $time;?></td>
<td><?php echo $row['subject'];?></td>
<td><?php echo $row['message'];?></td>
<td><?php
$cat = $row['category_id'];
if($cat == 1){
echo "Suggestion";
}
elseif ($cat == 2) {
echo "Claim";
}
else{
echo "Help";
}?></td>
</tr>
<tr >
<td colspan="6" class="hiddenRow">
<div class="accordian-body collapse" id="accordian_<?php echo $id; ?>"> Your Text here</div>
</td>
</tr>
<?php endwhile; ?>

Auto Payslip Printing using Javascript, PHP and MySqli for 500 employees

I am working on a payroll project and I am coding with php,html,js and mysql on xampp server. I have a salary sheet code which needs to be printed in pdf format for each employee with their names as the pdf filename.
on running the php page the js code triggers automatically and generates a pdf file with the filename as the employee name alongwith the employee salary data.
Now I need to generate all the employee payslips together in this format but automatically or maybe by clicking a single button.
I have done this project in vb6,ms-access with success but I am not well versed in javascript and now I am stuck here.
Any Help will be appreciated
<HTML>
<HEAD>
<TITLE>Salary Sheet</TITLE>
</HEAD>
<BODY>
<?php
include "connect.php";
$mysql = "SELECT * FROM emp_ndata LIMIT 0,1";
$myquery = mysqli_query($con, $mysql);
if(! $myquery ) {
die('Could not get data: ' . mysql_error());
}
$row = mysqli_fetch_array($myquery, MYSQLI_ASSOC);
?>
<div id="pdata">
<table class="table_for_showdata table_for_showdata_small">
<tr>
<th colspan="2">
Salary Sheet of <b class="table_for_showdata_lg">
<?php echo $row['Emp_Name']; ?></b> : <?php echo $row ['Emp_psmonth']; ?> , <?php echo $row ['Emp_psyear']; ?>
</th>
</tr>
<tr>
<td>Emp-Code</td>
<td><?php echo $row['Emp_ID']; ?></td>
</tr>
<tr>
<td>Designation</td>
<td><?php echo $row['Emp_Designation']; ?></td>
</tr>
<tr>
<th colspan="2">EARNINGS</th>
</tr>
<tr>
<td >Basic</td>
<td><?php echo round($row ['Emp_Basic']).".00"; ?></td>
</tr>
<tr>
<td >House Rent Allowance</td>
<td><?php echo round($row ['Emp_HRA']).".00"; ?></td>
</tr>
<tr>
<th >DEDUCTIONS</th>
<th> </th>
</tr>
<tr>
<td >Professional Tax</td>
<td><?php echo $row ['Emp_Proffessional_Tax'].".00"; ?></td>
</tr>
<tr>
<td >Provident Fund</td>
<td><?php echo $row ['Emp_Provident_Fund'].".00"; ?></td>
</tr>
<tr>
<th > </th>
<th> </th>
</tr>
<tr>
<td class="tab_head_blue"><b>TOTAL PAY : </td>
<td style="font-size:18px"><b>Rs.<?php echo $row ['Emp_Total_Pay'].".00"; ?></b></td>
</tr>
</table>
</div>
<script type="text/javascript">
function printDiv() {
var divToPrint = document.getElementById('pdata');
var popupWin = window.open('', '_blank', 'width=1100,height=400');
popupWin.document.open();
document.title = "<?php echo $row['Emp_Name']; ?>";
popupWin.document.write('<html><head><title>' + document.title + '</title>');
popupWin.document.write('<html><body onload="window.print()">' + divToPrint.innerHTML + '</html>');
popupWin.document.close();
}
</script>
<script>
printDiv();
</script>
</BODY></HTML>

How to hide the value in table and anchor tag when user click the anchor return

I want to hide the row when the admin click the anchor return because It's already saved in return.php so just need hide the returned status while the pending is not. Thank you for helping me
<thead>
<tr>
<th>Book title</th>
<th>Borrower</th>
<th>Type</th>
<th>Date Borrow</th>
<th>Due Date</th>
<th>Date Returned</th>
<th>Fines</th>
<th>Borrow Status</th>
</tr>
</thead>
<tbody>
<?php $user_query=mysqli_query($dbcon,"select * from borrow
LEFT JOIN member ON borrow.member_id = member.member_id
LEFT JOIN borrowdetails ON borrow.borrow_id = borrowdetails.borrow_id
LEFT JOIN book on borrowdetails.book_id = book.book_id
ORDER BY borrow.borrow_id DESC
")or die(mysqli_error());
while($row=mysqli_fetch_array($user_query)){
$currentdate = date('Y/m/d');
$start = new DateTime($returndate=$row['due_date']);
$end = new DateTime($currentdate);
$fines =0;
if(strtotime($currentdate) > strtotime($returndate)){
$days= $start->diff($end, true)->days;
$fines = $days > 0 ? intval(floor($days)) * 10 : 0;
$fi = $row['borrow_details_id'];
mysqli_query($dbcon,"update borrowdetails set fines='$fines' where borrow_details_id = '$fi'");
}
$id=$row['borrow_id'];
$book_id=$row['book_id'];
$borrow_details_id=$row['borrow_details_id'];
?>
<tr class="del<?php echo $id ?>">
<td><?php echo $row['book_title']; ?></td>
<td><?php echo $row['firstname']." ".$row['lastname']; ?></td>
<td><?php echo $row['type']; ?></td>
<td><?php echo $row['date_borrow']; ?></td>
<td><?php echo $row['due_date']; ?> </td>
<td><?php echo $row['date_return']; ?> </td>
<td><?php echo "₱ ".$fines; ?></td>
<td><?php echo $row['borrow_status'];?></td>
<td> <a rel="tooltip" title="Return" id="<?php echo $borrow_details_id; ?>"
href="#delete_book<?php echo $borrow_details_id; ?>" data-toggle="modal"
class="btn btn-success"><i class="icon-check icon-large"></i>Return</a>
<?php include('modal_return.php'); ?>
<td></td>
</tr>
<?php } ?>
</tbody>
</table>
This is the view_return.php where will admin see the all books pending
This is the history/transaction where the book is already return
For this , you can do like below example, Add a class "test" in anchorTag or in td
and by using jquery
$('.test').click(function(){
$(this).parent().hide();
});
<table>
<tr>
<td>Test</td>
<td class="test" id="returnId1">Return</td>
</tr>
<tr>
<td>Test2</td>
<td class="test" id="returnId2">Return</td>
</tr>
</table>

fetch view table values in another page while click on the button in codeigniter

i have one view candidates page in my application..in that page i display all the candidate details..in that page i gave one button called SCHEDULE INTERVIEW..when user click on the button i want to display that particular row candidates values in another page..i want to get only name and email of the particular candidate like:
Name:******
email:*******
like this i want to display that particular candidate details..
View page:
<div class="box-body">
<table id="example2" class="table table-bordered table-hover">
<thead>
<tr>
<th></th>
<th>First Name</th>
<th>Last Name</th>
<th>Email</th>
<th>Mobile Number</th>
<th>experience</th>
<th>CTC</th>
<th>Expected Ctc</th>
<th>role</th>
<th>Current Location</th>
<th>Desired Location</th>
<th>Notice Period</th>
<th>Resume</th>
<th>Actions</th>
</tr>
</thead>
<?php foreach ($view_candidates as $idata) { ?>
<tbody>
<tr id="domain<?php echo $idata->user_id;?>">
<td class="cell checkbox">
<input type="checkbox" class="selectedId" name="selectedId" />
</td>
<td><?php echo $idata->first_name;?></td>
<td><?php echo $idata->last_name;?></td>
<td><?php echo $idata->email;?></td>
<td><?php echo $idata->mobile_number;?></td>
<td><?php echo $idata->experience;?></td>
<td><?php echo $idata->ctc;?></td>
<td><?php echo $idata->expectedctc;?></td>
<td><?php echo $idata->role_name;?></td>
<td><?php echo $idata->current_location;?></td>
<td><?php echo $idata->desired_location;?></td>
<td><?php echo $idata->notice_period;?></td>
<td><?php echo $idata->resume;?></td>
<td>
Schedule interview
</td>
</tr>
</tbody>
Can anyone help me..
How to do this..
Thanks in Advance..
Something like below:
<?php
// controller
function candidate_detail($candidateid)
{
$data = $this->model_name->get_candidate_detail($candidateid);
$viewData['getCandidate'] = $data;
$this->load->view('candidate_view',$viewData);
}
// model
function get_candidate_detail($candidateid)
{
$q = $this->db->query("SELECT * FROM tbl_name WHERE candidate_id = $candidateid");
if($q->num_rows() > 0) {
return $q->row_array();
} else {
return '';
}
}
?>
// view candidate_view
<div class="box-body">
<table id="example2" class="table table-bordered table-hover">
<thead>
<tr>
<th></th>
<th>First Name</th>
<th>Last Name</th>
<th>Email</th>
<th>Mobile Number</th>
<th>experience</th>
<th>CTC</th>
<th>Expected Ctc</th>
<th>role</th>
<th>Current Location</th>
<th>Desired Location</th>
<th>Notice Period</th>
<th>Resume</th>
</tr>
</thead>
<tbody>
<tr id="domain<?php echo $getCandidate['user_id'];?>">
<td class="cell checkbox">
<input type="checkbox" class="selectedId" name="selectedId" />
</td>
<td><?php echo $getCandidate['first_name'];?></td>
<td><?php echo $getCandidate['last_name'];?></td>
<td><?php echo $getCandidate['email'];?></td>
<td><?php echo $getCandidate['mobile_number'];?></td>
<td><?php echo $getCandidate['experience'];?></td>
<td><?php echo $getCandidate['ctc'];?></td>
<td><?php echo $getCandidate['expectedctc'];?></td>
<td><?php echo $getCandidate['role_name'];?></td>
<td><?php echo $getCandidate['current_location'];?></td>
<td><?php echo $getCandidate['desired_location'];?></td>
<td><?php echo $getCandidate['notice_period'];?></td>
<td><?php echo $getCandidate['resume'];?></td>
</tr>
</tbody>

Categories

Resources