My Model
public function get_dat($start_date, $end_date) {
$this->db->select('*');
$this->db->from('jil_mroproducts');
$query = $this->db->get();
if ($query->num_rows() > 0) {
$sum=0;
foreach ($query->result() as $row) {
$this->db->select('*,sum(pocd_sellingprice) as gg');
$this->db->from('jil_jikwarehouse');
$this->db->join('jil_pojmdetail', 'jil_pojmdetail.pojd_id=' . $this->table4 . '.ware_poid', 'left');
$this->db->join('jil_pocjdetail', 'jil_pocjdetail.pocd_qumjid=jil_pojmdetail.pojd_qumjid', 'left');
$this->db->join('jil_users', 'jil_users.usr_id=jil_pojmdetail.pojd_customerid', 'left');
$this->db->group_by('jil_jikwarehouse.ware_productid');
$this->db->where('jil_jikwarehouse.ware_productid', $row->mro_id);
$this->db->where('jil_jikwarehouse.ware_time >=', $start_date);
$this->db->where('jil_jikwarehouse.ware_time <=', $end_date);
$query1 = $this->db->get();
if ($query1->num_rows() > 0) {
$data[] = $row;
}
foreach ($query1->result() as $row) {
$sum+=$row->pocd_sellingprice;
$data[] = $row;
}
$data[]['subtotal']=$sum;// here am trying to get subtotal
}
return $data;
}
return false;
}
VIEW
<table style="width: 100%">
<tr>
<th style="width: 5px">PO ID</th>
<th style="width: 5px">PO Dated</th>
<th style="width: 50px">PO Quantity</th>
<th style="width: 10px">Purchase Value</th>
<th style="width: 10px">Available Stock</th>
<th style="width: 5px">PO Customer ID</th>
<th style="width: 5px">PO Dated</th>
<th style="width: 50px">PO Quantity</th>
<th style="width: 10px">Sale Value</th>
</tr>
<?php
$slno = 0;
$pur=0;
$sel=0;
if (!empty($list)) {
foreach ($list as $user_fetcheach) {
?>
<tr><td colspan="6" style="text-align:left;"><?php echo '<h4>' . $user_fetcheach->mro_name . '</h4>'; ?></td></tr>
<?php if (!empty($user_fetcheach->ware_id)) {
$pur+=$user_fetcheach->pojd_sellingprice;
$sel+=$user_fetcheach->pocd_sellingprice;
$slno++; ?>
<tr>
<td><?php echo $user_fetcheach->ware_pomainid.'-'.$user_fetcheach->ware_poid; ?></td>
<td><?php echo date('d-m-Y',$user_fetcheach->pojd_dated); ?></td>
<td><?php echo $user_fetcheach->pojd_quantity; ?></td>
<td><?php echo $user_fetcheach->pojd_sellingprice; ?></td>
<td><?php echo $user_fetcheach->ware_quantity; ?></td>
<td><?php echo $user_fetcheach->pocd_id.'-'.$user_fetcheach->pocd_pocjid; ?></td>
<td><?php echo date('d-m-Y',$user_fetcheach->pocd_dated); ?></td>
<td><?php echo $user_fetcheach->pocd_quantity; ?></td>
<td><?php echo $user_fetcheach->pocd_sellingprice; ?></td>
</tr>
<?php } ?>
<?php
}
}
?>
<tr><td><b>Grand Total:-</b></td><td></td><td></td><td><?php echo $pur;?></td><td></td><td></td><td></td><td></td><td><?php echo $sel;?></td></tr>
</table>[![enter image description here][1]][1]
Currently am getting a view like this,am trying to display subtotal of each product in the marked place but not getting, please help if anybody can help.
i am getting each row based on each product,also grand total is displayed. please help me to display subtotal of each product
Related
I am using DataTables and I want to add new TR at the end of while loop.
I know we can add <tfoot></tfoot>, but I don't want to add '' because I am filtering data with custom Ajax.
I have tried below code but it's not working:
<?php
$Itesres = mysqli_query($con_db,"SELECT * FROM tbl_area ORDER BY `tbl_area`.`name` ASC");
while($ItemResult = mysqli_fetch_array($Itesres)){
?>
<table id="printData" class="table table-bordered table-hover ">
<thead>
<tr>
<th>Group</th>
<th>Party Name</th>
<th>Balance</th>
</tr>
</thead>
<tbody id="getGroups">
<?php
$i = 1;
while($row = mysqli_fetch_array($sdetails)){
$totalAmount += $row['total_debtors'];
$i++;
?>
<tr>
<td><?php echo getAreaName($row['area_id']); ?></td>
<td><?php echo GrabAccountIDName($row['client_id']); ?></td>
<td><?php echo abs($row['total_debtors']); ?></td>
</tr>
<?php if( $i == ( $numRows - 1 ) ) { ?>
<tr>
<td> </td>
<td style="text-align:right">Total:</td>
<td><?php echo abs($totalAmount); ?></td>
</tr>
<?php } } ?>
</tbody>
</table>
Also, when I use <tfoot></tfoot> it's not printable.
Probably your problem is in $numRows which is not defined.
So you can try this:
<?php
$Itesres = mysqli_query($con_db,"SELECT * FROM tbl_area ORDER BY `tbl_area`.`name` ASC");
$numRows = mysqli_num_rows($Itesres);
while($ItemResult = mysqli_fetch_array($Itesres)){
?>
<table id="printData" class="table table-bordered table-hover ">
<thead>
<tr>
<th>Group</th>
<th>Party Name</th>
<th>Balance</th>
</tr>
</thead>
<tbody id="getGroups">
<?php
$i = 1;
while($row = mysqli_fetch_array($sdetails)){
$totalAmount += $row['total_debtors'];
$i++;
?>
<tr>
<td><?php echo getAreaName($row['area_id']); ?></td>
<td><?php echo GrabAccountIDName($row['client_id']); ?></td>
<td><?php echo abs($row['total_debtors']); ?></td>
</tr>
<?php if( $i == ( $numRows - 1 ) ) { ?>
<tr>
<td> </td>
<td style="text-align:right">Total:</td>
<td><?php echo abs($totalAmount); ?></td>
</tr>
<?php } } ?>
</tbody>
</table>
I have a foreach in the table. I foreach a row for every row in my database. So my database has got 10 records, I and my table is showing all those records underneath eachother. So far so good.
I want to number them, from 1 to 10, displayed in front of every row.
This is my table:
<table class="table table-striped mt-3">
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">Team</th>
<th scope="col">Player</th>
<th scope="col">P</th>
<th scope="col">W</th>
<th scope="col">D</th>
<th scope="col">L</th>
<th scope="col">GF</th>
<th scope="col">GA</th>
<th scope="col">GD</th>
<th scope="col">P</th>
</tr>
</thead>
<tbody>
<?php $count = count($table); ?>
<?php foreach($table as $t): ?>
<tr>
<td><?php for($i = 1; $i < $count; $i++;)
{
echo $i; ?>}
</td>
<td><?php echo $t['team']; ?></td>
<td><?php echo $t['speler']; ?></td>
<td><?php echo $t['gw']; ?></td>
<td><?php echo $t['w']; ?></td>
<td><?php echo $t['g']; ?></td>
<td><?php echo $t['v']; ?></td>
<td><?php echo $t['dv']; ?></td>
<td><?php echo $t['dt']; ?></td>
<td><?php echo $t['ds']; ?></td>
<td><?php echo $t['points']; ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
This is my method
public function fifaLeagueTable() {
$getTable = "SELECT * FROM fifa_league ORDER BY points DESC";
$table = $this->model->readAll($getTable);
$count = count($table);
include('app/views/fifaLeagueTable.php');
}
If I var_dump the $count, I receive int(10). So it's counting the amount of rows and I have access to the 10. I am getting a white page, so there might be something wrong in the for loop or something. What did I do wrong?
You just need to create one more variable and its done. Here is updated code :
<table class="table table-striped mt-3">
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">Team</th>
<th scope="col">Player</th>
<th scope="col">P</th>
<th scope="col">W</th>
<th scope="col">D</th>
<th scope="col">L</th>
<th scope="col">GF</th>
<th scope="col">GA</th>
<th scope="col">GD</th>
<th scope="col">P</th>
</tr>
</thead>
<tbody>
<?php $count = count($table); $num = 1; ?>
<?php foreach($table as $t): ?>
<tr>
<td><?php echo $num; ?>
</td>
<td><?php echo $t['team']; ?></td>
<td><?php echo $t['speler']; ?></td>
<td><?php echo $t['gw']; ?></td>
<td><?php echo $t['w']; ?></td>
<td><?php echo $t['g']; ?></td>
<td><?php echo $t['v']; ?></td>
<td><?php echo $t['dv']; ?></td>
<td><?php echo $t['dt']; ?></td>
<td><?php echo $t['ds']; ?></td>
<td><?php echo $t['points']; ?></td>
</tr>
<?php $num++ ; endforeach; ?>
</tbody>
</table>
Good Day, i'm struggling with this code..
The result "10" is set $fod but this needs to be replaced to display the called row's id so that the SQL WHERE can list the correct data inside the relevant row. See Image for the Result i'm getting.
See Current Result and Desired Result
As you can see i need ROW ID 10 to display 10's items and ROW ID 11 to display 11's items. Please assist me, how can i call these rows to display correctly?
Calling function:
Controller.php
$data['order_list'] = $this->product->data_ordershalf();
$fod = 10;
$data['order_listfull'] = $this->product->data_ordersfull($fod);
Functions.php:
function data_ordershalf(){
$this->db->select('*');
$this->db->join('order_detail', 'order_detail.orderid=orders.id', 'left');
$this->db->join('customers', 'customers.id=orders.customerid', 'left');
$this->db->join('testshop_products', 'testshop_products.product_id=order_detail.productid', 'left');
$this->db->from('orders');
$this->db->group_by('orderid');
$rs = $this->db->get();
return $rs->result_array();
}
function data_ordersfull($fod){
$this->db->select('*');
$this->db->join('orders', 'orders.id=order_detail.orderid', 'left');
$this->db->join('testshop_products', 'testshop_products.product_id=order_detail.productid', 'left');
$this->db->from('order_detail');
$this->db->where('orderid',$fod);
$rs = $this->db->get();
return $rs->result_array();
View.php:
<?php if(!$order_list){ ?>
<tbody>
<tr>
<th colspan="7"><center>No orders placed</center></th>
</tr>
</tbody>
<?php } else { $sr = 1; ?>
<tbody>
<?php foreach( $order_list as $row) { ?>
<tr>
<th scope="row"><?php echo $row['id']; ?></th>
<td><?php echo $row['date']; ?></td>
<td><?php echo $row['name']; ?></td>
<td>
<table>
<?php foreach( $order_listfull as $row2) { ?>
<tr>
<th scope="row"><?php echo $row2['id']; ?></th>
<td><?php echo $row2['product_name']; ?></td>
<td><?php echo $row2['quantity']; ?></td>
<td></td>
<td><?php echo $row2['price']; ?></td>
</tr>
<?php } ?>
</table>
</td>
<td><?php echo $row['quantity']; ?></td>
<td><?php echo $row['price']; ?></td>
</tr>
<?php } ?>
</tbody>
<?php } ?>
You can create helper and put following function it.
function data_ordersfull($fod){
$this->db->select('*');
$this->db->join('orders', 'orders.id=order_detail.orderid', 'left');
$this->db->join('testshop_products', 'testshop_products.product_id=order_detail.productid', 'left');
$this->db->from('order_detail');
$this->db->where('orderid',$fod);
$rs = $this->db->get();
return $rs->result_array();
}
====================View.php======================================
<?php if(!$order_list){ ?>
<tbody>
<tr>
<th colspan="7"><center>No orders placed</center></th>
</tr>
</tbody>
<?php } else { $sr = 1; ?>
<tbody>
<?php foreach( $order_list as $row) {
$order_listfull=data_ordersfull($row['id']);
?>
<tr>
<th scope="row"><?php echo $row['id']; ?></th>
<td><?php echo $row['date']; ?></td>
<td><?php echo $row['name']; ?></td>
<td><table>
<?php foreach( $order_listfull as $row2) { ?>
<tr>
<th scope="row"><?php echo $row2['id']; ?></th>
<td><?php echo $row2['product_name']; ?></td>
<td><?php echo $row2['quantity']; ?></td>
<td></td>
<td><?php echo $row2['price']; ?></td>
</tr>
<?php } ?></table></td>
<td><?php echo $row['quantity']; ?></td>
<td><?php echo $row['price']; ?></td>
</tr>
<?php } ?>
</tbody>
<?php } ?>
function data_ordershalf(){
$this->db->select('*');
$this->db->from('orders');
$this->db->join('order_detail', 'order_detail.orderid=orders.id', 'left');
$this->db->join('customers', 'customers.id=orders.customerid', 'left');
$this->db->join('testshop_products', 'testshop_products.product_id=order_detail.productid', 'left');
$this->db->group_by('order_detail.orderid');
$rs = $this->db->get();
return $rs->result_array();
}
function data_ordersfull($fod){
$this->db->select('*');
$this->db->from('order_detail');
$this->db->join('orders', 'orders.id=order_detail.orderid', 'left');
$this->db->join('testshop_products', 'testshop_products.product_id=order_detail.productid', 'left');
$this->db->where('order_detail.orderid',$fod);
$rs = $this->db->get();
return $rs->result_array();
i want to display data in specific format that i have attached. Every object,Title and Coordinates added by instructor should be displayed in front of instructor in one row . This is what i want . this is how i am currently getting data
Code for both view and controller is here
<table id="example2" class="table table-bordered table-hover">
<thead>
<tr>
<th>#</th>
<th>Instructor</th>
<th>Title</th>
<th>Coordinates</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<?php $i=1; foreach ($res as $value) { ?>
<tr>
<td><?php echo $i++; ?></td>
<td><?php echo $value['first_name'] . " " . $value['last_name']; ?></td>
<td><?php echo $value['description']; ?></td>
<td><?php echo $value['coordinates']; ?></td>
<td>
<?php if($edit_delete['edit']) {?>
<i class="fa fa-eye"></i>
<?php } ?>
</td>
</tr>
<?php } ?>
</tbody>
</table>
public function index()
{
$this->user_model->check_permissions('Objects/index');
$data['edit_delete']=$this->user_model->checkEditDelete('Objects/index');
$rl_id= $this->rol_id;
$str = implode('-',$rl_id);
if($str==2)
{
$data['menu']=$this->load_model->menu_inst();
}else
{
$data['menu']=$this->load_model->menu();
}
$data['base_url'] = base_url();
$data['userInfo'] = $this->userInfo;
$rl_id= $this->rol_id;
$super = implode('-',$rl_id);
if($super==1)
{
$this->db->select('object.id, object.description, object.coordinates, admin.first_name, admin.last_name');
$this->db->from('object');
$this->db->join('admin', 'admin.id = object.instructor_id');
$this->db->where('admin.is_delete',0);
$this->db->where('admin.role_id',2);
$this->db->where('object.is_delete',0);
$data['res'] = $this->db->get()->result_array();
}
else
{
$in_id= $this->insret_id;
$insrtuctur = implode('-',$in_id);
$data['data'] = $this->db->where('is_delete',0)->where('instructor_id',$insrtuctur)->get('object')->result_array();
}
$data['page'] = "objects/objects";
$this->load->view('Template/main', $data);
}
I do have some problems with my code.
I would like to change the color on my lables if it goes from one status to another depending on the world from mysql db.
First of all, I have the code:
<table class="table responsive">
<div id="employee_table">
<table class="table">
<tr>
<th width="10%">ARK ID</th>
<th width="20%">User</th>
<th width="45%">Header</th>
<th width="10%">Status</th>
<th width="20%">Priority</th>
</tr>
<?php
while($row = mysqli_fetch_array($result))
{
?>
<tr>
<td><?php echo $row["ark_id"]; ?></td>
<td><?php echo $row["name"]; ?></td>
<td><a href="read.php?id=<?php echo $row['id']; ?>"><?php echo $row["overskrift"]; ?></td>
<td><?php echo $row["prioritet"]; ?></td>
<td><?php echo $row["status"]; ?></td>
</tr>
<?php
}
?>
</table>
Second of all, I'll have Status and priority to change label color like this
If priority is LOW then Green Label
If priority is MEDIUM then Blue
if priority is HIGH then RED
... The same function to the Status Pending .... And so on..
I hope someone could help me :)
Thanks!
You could check the priority on the beginning of the while loop:
<table class="table responsive">
<div id="employee_table">
<table class="table">
<tr>
<th width="10%">ARK ID</th>
<th width="20%">User</th>
<th width="45%">Header</th>
<th width="10%">Status</th>
<th width="20%">Priority</th>
</tr>
<?php
while($row = mysqli_fetch_array($result))
{
if($row["prioritet"] == "LOW") {
$color = '#000000'; // choose color
}
else if($row["prioritet"] == "MEDIUM") {
$color = '#888888'; // choose color
}
else {
$color = '#ffffff'; // choose color
}
?>
<tr>
<td><?php echo $row["ark_id"]; ?></td>
<td><?php echo $row["name"]; ?></td>
<td><a href="read.php?id=<?php echo $row['id']; ?>"><?php echo $row["overskrift"]; ?></td>
<td style="color:<?php echo $color?>"><?php echo $row["prioritet"]; ?></td>
<td style="color:<?php echo $color?>"><?php echo $row["status"]; ?></td>
</tr>
<?php
}
?>
</table>
hope below code help you
<table class="table responsive">
<div id="employee_table">
<table class="table">
<tr>
<th width="10%">ARK ID</th>
<th width="20%">User</th>
<th width="45%">Header</th>
<th width="10%">Status</th>
<th width="20%">Priority</th>
</tr>
<?php
while($row = mysqli_fetch_array($result))
{
if($row["prioritet"] == "LOW") {
$priority_color = '#009933'; // low priority color
}
else if($row["prioritet"] == "MEDIUM") {
$priority_color = '#0099ff'; // Medium priority color
}
else if($row["prioritet"] == "HIGH"){
$priority_color = '#ff0000'; // High priority color
}else{
$priority_color = '#ffffff'; // default color
}
?>
<tr>
<td><?php echo $row["ark_id"]; ?></td>
<td><?php echo $row["name"]; ?></td>
<td><a href="read.php?id=<?php echo $row['id']; ?>"><?php echo $row["overskrift"]; ?></td>
<td><?php echo $row["prioritet"]; ?></td>
<td bgcolor="<?php echo $priority_color; ?>"><?php echo $row["status"]; ?></td>
</tr>
<?php
}
?>
</table>