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);
}
Related
I have displayed a table of data from MYSQL DB. I have a button to export to excel. When I click on the button the excel file is created but it is empty or sometimes nothing is happening. What could be wrong here?
I have code like below:
view.php:
<div id="div_users">
<table class="table table-striped">
<thead class="thead-dark">
<tr>
<th class="mn_th01">#</th>
<th class="mn_th02">Date</th>
<th class="mn_th03">Name</th>
<th class="mn_th04">Place</th>
<th class="mn_th05">Notes</th>
<th class="mn_th06">Sales Exec.</th>
<th class="mn_th07">Image</th>
</tr>
</thead>
<tbody>
<?php
date_default_timezone_set('Asia/Kolkata');
$date = date('d/m/Y', time());
echo $date . "\n";
$count=1;
$query = "SELECT * FROM ua_myadd_details WHERE STR_TO_DATE(notes_date,'%d/%m/%y') = STR_TO_DATE('$date', '%d/%m/%y') ORDER BY M.id DESC";
$result = mysqli_query($bd,$query);
if(mysqli_num_rows($result) > 0)
{
while($row = mysqli_fetch_assoc($result)) {
?>
<tr>
<td><?php echo $count; ?></td>
<td><?php echo $row["notes_date"]; ?></td>
<td><?php echo $row["firstname"] . " " . $row["lastname"]; ?></td>
<td><?php echo $row["city"]; ?></td>
<td><?php echo $row["notes"]; ?></td>
<td><?php echo $row["executive"]; ?></td>
</tr>
<?php $count++; }
}
else
{?>
<tr>
<td colspan="7">
<?php echo "No Data Found"; ?>
</td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
I have a button like this:
<div class="col-md-3">
<button name="create_excel" id="create_excel" class="btn btn-success btn-block"><i class="fas fa-arrow-alt-circle-down"></i> Export to Excel</button>
</div>
In the script I have written:
<script>
$(document).ready(function(){
$('#create_excel').click(function(){
var excel_data = $('#div_users').html();
var page = "export.php?data=" + excel_data;
window.location = page;
});
});
</script>
export.php:
<?php
header('Content-Type: application/vnd.ms-excel');
header('Content-disposition: attachment; filename='.rand().'.xls');
echo $_GET["data"];
?>
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 this three tables that i joined, those tables are: attendance, employee, and division
this is my model to show the data
function lihatData()
{
$this->db->select('attendance.emp_code, attendance.emp_name,division.name_division,attendance.date,attendance.time_in, attendance.time_out');
$this->db->from('attendance');
$this->db->join('employee', 'employee.emp_code = attendance.emp_code');
$this->db->join('division', 'employee.id_division = divisiob.id_division');
$this->db->where_in('division.id_division',$this->session->userdata('id_division')
}
this is my view
<table class="table table-striped table-bordered table-hover">
<thead>
<tr>
<th><center>No</center></th>
<th><center>EMP CODE</center></th>
<th><center>NAME</center></th>
<th><center>DIVISION</center></th>
<th><center>DATE</center></th>
<th><center>TIME IN</center></th>
<th><center>TIME OUT</center></th>
</tr>
</thead>
<tbody>
<?php
$no = 1;
if(is_array($data)){
foreach($data as $row){
?>
<tr>
<td><?php echo $no++;?></td>
<td><?php echo $row->emp_code; ?></td>
<td><?php echo $row->emp_name; ?></td>
<td><?php echo $row->name_division; ?></td>
<td><?php echo date("d-m-Y", strtotime($row->date))?></td>
<td><?php echo $row->time_in; ?></td>
<td><?php echo $row->time_out; ?></td>
</tr>
<?php } }?>
</tbody>
</table>
This is what i got from my code:
So what i need to change the results into something like this:
Division : Redaksi (based on user's division)
-------------------------------------------------------------------
| emp code | name | date | time in | time out |
-------------------------------------------------------------------
UPDATE: I already managed to group the division into a table, and here's the result:
As you can see, its already show datas of user's division. but i need to remove the division table, and change it into some kind of table's name or put the division's name at the top of the table based on user's name
a possible solution would be to extract data from your first array Item, something like the following should work
<?php
if (is_array($data) && count($data) > 0)
{
?>
<h1><?=$data[0]->nama_division; ?></h1>
<?php
}
?>
<table class="table table-striped table-bordered table-hover">
<thead>
<tr>
<th><center>No</center></th>
<th><center>EMP CODE</center></th>
<th><center>NAME</center></th>
<th><center>DATE</center></th>
<th><center>TIME IN</center></th>
<th><center>TIME OUT</center></th>
</tr>
</thead>
<tbody>
<?php
$no = 1;
if(is_array($data))
{
foreach($data as $row){
?>
<tr>
<td><?php echo $no++;?></td>
<td><?php echo $row->emp_code; ?></td>
<td><?php echo $row->emp_name; ?></td>
<td><?php echo date("d-m-Y", strtotime($row->date))?></td>
<td><?php echo $row->time_in; ?></td>
<td><?php echo $row->time_out; ?></td>
</tr>
<?php
}
}
?>
</tbody>
</table>
function lihatData()
{
$this->db->from('attendance');
$this->db->join('employee', 'employee.emp_code = attendance.emp_code');
$this->db->join('division', 'employee.id_division = divisiob.id_division');
$this->db->where_in('division.id_division',$division);
return $this->db->get()->result();
}
try this
The key is how to group result by division. I think you can sort the result array by division, or group it as follow:
$sortedResult = [];
foreach ($data as $row) {
$sortedResult[$row->name_division] = $row;
}
//Render
<?php foreach ($sortedResult as $devision => $data) { ?>
<div><?php echo $devision; ?></div>
<table class="table table-striped table-bordered table-hover">
<thead>
<tr>
<th><center>No</center></th>
<th><center>EMP CODE</center></th>
<th><center>NAME</center></th>
<th><center>DATE</center></th>
<th><center>TIME IN</center></th>
<th><center>TIME OUT</center></th>
</tr>
</thead>
<tbody>
<?php
$no = 1;
foreach($data as $row){
?>
<tr>
<td><?php echo $no++;?></td>
<td><?php echo $row->emp_code; ?></td>
<td><?php echo $row->emp_name; ?></td>
<td><?php echo date("d-m-Y", strtotime($row->date))?></td>
<td><?php echo $row->time_in; ?></td>
<td><?php echo $row->time_out; ?></td>
</tr>
<?php }?>
</tbody>
</table>
<?php } ?>
I would like to ask on how to make my table to appear as following:
But I only manage to get my table to appear like this:
As you can see, the table is separated according to the different year or semester of when they stored their stuff. It is basically a history storage of that particular person. Unfortunately, I don't know how to make the generated table to attach together for the one with same year and semester instead of separating it. Even the numbering is affected. Below is the code that I have so far:
<?php
include("connect.php");
include("header.php");
if(isset($_GET['invstuview_bag'], $_GET['invstuview_name']))
{
$get_id = $_GET['invstuview_bag'];
$get_name = $_GET['invstuview_name'];
?>
<br/>
<ul class="breadcrumb">
<li class="breadcrumb-item">View History</li>
<li class="breadcrumb-item-active">Baggage Detail History</a></li>
</ul>
<div id="cssword">Baggage Detail History For <?php echo $get_name; ?>(<?php echo $get_id; ?>)</div>
<div class="container" style="width:70%;">
<div class="table-responsive">
<?php
$sql_join = "SELECT student.*,location.*, inventory.*, baggage.*
FROM
student,location, inventory, baggage
WHERE
student.student_id = inventory.invstu_id AND
baggage.baggage_id = inventory.invbag_id AND
location.location_id = inventory.invloc_id AND
invstu_id = '$get_id'
ORDER BY inventory_id";
$result_join= mysqli_query($connect,$sql_join);
$prev_year = "";
$prev_sem = 0;
$get_year = "";
$get_sem = 0;
while($row_join=mysqli_fetch_assoc($result_join))
{
$counter = 1;
$prev_year = $row_join["invstu_year"];
$prev_sem = $row_join["invstu_sem"];
//if the data is of same year and semester
if(($prev_year!="") && ($prev_sem!=0) && ($prev_year == $get_year) && ($prev_sem == $get_sem))
{
$get_year = $row_join["invstu_year"];
$get_sem = $row_join["invstu_sem"];
?>
<table class="table table-bordered">
<tr>
<th>No.</th>
<th>Baggage Types</th>
<th>Quantity</th>
<th>Location</th>
</tr>
<tr>
<td><?php echo $counter; ?></td>
<td><?php echo $row_join["baggage_type"]; ?></td>
<td><?php echo $row_join["invbag_quantity"]; ?></td>
<td><?php echo $row_join["location_house"]; ?></td>
</tr>
<?php
$counter++;
echo'</table>';
}
//if data is not of same year or semester
else
{
$get_year = $row_join["invstu_year"];
$get_sem = $row_join["invstu_sem"];
?>
</br></br>
Room: <?php echo $row_join["invstu_room"]; ?><br/>
Year: <?php echo $row_join["invstu_year"]; ?><br/>
Semester: <?php echo $row_join["invstu_sem"]; ?><br/>
<table class="table table-bordered">
<tr>
<th>No.</th>
<th>Baggage Types</th>
<th>Quantity</th>
<th>Location</th>
</tr>
<tr>
<td><?php echo $counter; ?></td>
<td><?php echo $row_join["baggage_type"]; ?></td>
<td><?php echo $row_join["invbag_quantity"]; ?></td>
<td><?php echo $row_join["location_house"]; ?></td>
</tr>
<?php
$counter++;
echo'</table>';
}
}
?>
</div>
<div align="right">
<button type="button" name="back" class="btn btn-success" id="back" style="width:200px; display:inline-block; margin-top:2%; margin-bottom:1%; background-color: #4CAF50" onclick="window.location.href='view.php'">Back</button>
</div>
</div>
<?php
}
?>
Any ideas is highly appreciated.
Move these out of the while loop:
<table class="table table-bordered">
<tr>
<th>No.</th>
<th>Baggage Types</th>
<th>Quantity</th>
<th>Location</th>
</tr>
echo'</table>';
I have to print something like No emails found in my view.
My Controller looks:
public function viewEmailMessage()
{
if(($this->session->userdata('username')!=""))
{
$data =array();
$data['email']=$this->adminModel->viewEmailMessageModel();
$this->load->view('admin/viewEmailMessages',$data);
}
else
{
$this->load->view('admin/login');
}
}
My Model looks:
public function viewEmailMessageModel()
{
$this->db->select("*");
$this->db->from('message');
$this->db->order_by("id", "desc");
$query = $this->db->get();
return $result=$query->result();
}
My View looks:
<h4>View Emails</h4>
<table class="table">
<thead>
<tr>
<th>Id</th>
<th>Name</th>
<th>Email</th>
<th>Message</th>
<th>options</th>
</tr>
</thead>
<tbody>
<?php
foreach ($email as $row)
{
?>
<tr>
<td><?php echo $row->id;?></td>
<td><?php echo $row->name;?></td>
<td><?php echo $row->email;?></td>
<td><?php echo $row->message;?></td>
<td>
<i class="fa fa-trash fa-lg "></i>
</td>
</tr>
<?php }
?>
</tbody>
</table>
How to modify my Controller, model & view. For I have to print something like "No Emails Found" in the same view when the message table is empty.
In view try this
<h4>View Emails</h4>
<table class="table">
<thead>
<tr>
<th>Id</th>
<th>Name</th>
<th>Email</th>
<th>Message</th>
<th>options</th>
</tr>
</thead>
<tbody>
<?php
if(count($email) > 0 ){
foreach ($email as $row)
{
?>
<tr>
<td><?php echo $row->id;?></td>
<td><?php echo $row->name;?></td>
<td><?php echo $row->email;?></td>
<td><?php echo $row->message;?></td>
<td>
<i class="fa fa-trash fa-lg "></i>
</td>
</tr>
<?php }
} else {
echo "msg here";
}
?>
</tbody>
</table>
<h4>View Emails</h4>
<table class="table">
<thead>
<tr>
<th>Id</th>
<th>Name</th>
<th>Email</th>
<th>Message</th>
<th>options</th>
</tr>
</thead>
<tbody>
<?php
if($email and other condition){
foreach ($email as $row)
{
?>
<tr>
<td><?php echo $row->id;?></td>
<td><?php echo $row->name;?></td>
<td><?php echo $row->email;?></td>
<td><?php echo $row->message;?></td>
<td>
<i class="fa fa-trash fa-lg "></i>
</td>
</tr>
<?php }
}
else{
echo your message;
}
?>
</tbody>
</table>
use count() function
and not able to use if(!empty($email)) for array variable use count()
if(count($email)==0)
{
echo "NO email found";
}
else
{
foreach($email as $row)
{
.........
}
}