abscondingsince is a date field with value 2016-08-24 and dateofcontactviaphone is a date field with value 2016-08-26 . when I try to echo timespan($row['absconding since'], $row['dateofcontactviaphone']); its giving 2016-08-2446 Years, 8 Months, 3 Days, 5 Hours, 43 Minutes as the output whereas it should have been 2 days and so on. I have no clue where I am making a mistake. My view code is as below:
<table cellpadding="10px" border="1" style="background:none;width:75%;" RULES="ROWS" class="tab_data">
<thead>
<th>Employee Name</th>
<th>Absconding Since</th>
<th>Absconding Days</th>
<th>Phone Log</th>
<th>Comments on call made</th>
<th>Date of Email Sent</th>
<th>Comments/responses to email recorded</th>
<th>View Absconding Checklist</th>
</thead>
<tbody>
<?php
$serial_no = 1;
$i = 0;
foreach($rows as $row){
$i++;
?>
<tr>
<td style="width:10%">
<?php echo $row['name']; ?>
</td>
</td>
<td style="width:10%">
<?php echo $row['abscondingsince'];
echo timespan($row['abscondingsince'], $row['dateofcontactviaphone']);
?>
</td>
<td style="width:10%">
<?php echo $row['dateofcontactviaphone']; ?>
</td>
<td style="width:10%">
<?php echo $row['commentsphone']; ?>
</td>
<td style="width:10%">
<?php echo $row['dateofcontactviaemail']; ?>
</td>
<td style="width:10%">
<?php echo $row['commentsemail']; ?>
</td>
<td style="width:10%">
<?php
if ($row['last_status'] == 'Accepted'){
echo anchor('exits/view_exit_checklist/'.$row['id'],"<i class='fa fa-eye edit_row' alt='View' title='Edit' rel='".$row['id']."' ></i>",array('rel'=>$row->id,'class'=>'edit_row'));
}
else
{
echo "NA";
}
?>
</td>
</tr>
<?php
} ?>
</tbody>
</table>
Use like this:-
echo timespan(strtotime($row['absconding since']),
strtotime($row['dateofcontactviaphone']));
Related
I am having a nested table with a while loop, I want to add one more nested table in the same row:
Now I want to add one more nested table as each cd contains more than one data like below:
My code is as follows
<?php
if(isset($_POST['viewcd'])){
$queryw = "select * from lib_cd where id=".$_POST['idd'];
$resultw = $mysqli->query($queryw);
?>
<div>
<table border="1">
<thead>
<tr ><th >Select</th>
<th>Well_Number</th>
<th>Well_Name</th>
<th>CD No:</th>
<th >Logs</th>
</tr>
</thead>
<?php
while($rowcd = $resultw->fetch_assoc()){
?>
<tr>
<td><?php echo $rowcd['id'] ?> </td>
<td><?php echo $rowcd['well_no'] ?></td>
<td><?php echo $rowcd['well_name'] ?></td>
<td>
<table border="1" width="100%">
<?php
$querycd = "select * from cd where pidd=".$rowcd['id'];
$resultcd = $mysqli->query($querycd);
while($rowcd = $resultcd->fetch_assoc()){
?>
<tr>
<td ><?php echo $rowcd['cd_no'] ?></td>
/* I want to add one more nested table here*/
</tr>
<?php
}
?>
</table>
</td>
</tr>
<?php
}
}
?>
</table>
</div>
I tried some thing like this,after my second while loop
while($rowcd = $resultcd->fetch_assoc()){
?>
<tr>
<td ><?php echo $rowcd['cd_no'] ?></td>
<td>
<table>
<?php
$queryl = "select * from lib_cd_logs where pid=".$rowcd['cd_no'];
$resultl = $mysqli->query($queryl);
while($rowl = $resultl->fetch_assoc()){
?>
<tr>
<td><?php echo $rowl['logs'] ?></td>
</tr>
<?php
}
?>
</tr>
<?php
}
?>
</table>
</td>
</tr>
<?php
}
}
?>
</table>
</div>
but the result was messed up. I am confused, where I want to end my while loop, I think.
Finally i got as i wish, and i am sharing the code as below
<?php
if(isset($_POST['viewcd'])){
$queryw = "select * from lib_cd where id=".$_POST['idd'];
$resultw = $mysqli->query($queryw);
?>
<div class="container">
<table border="1" align="center" border-collapse="collapse">
<thead>
<tr >
<th >Select</th>
<th>Well_Number</th>
<th>Well_Name</th>
<th width="100">CD No:</th>
<th width="150">Logs</th>
<th width="100">Bottom Depth</th>
<th width="100">Top Depth</th>
<th width="100">Date of Log</th>
</tr>
</thead>
<?php
while($rowcd = $resultw->fetch_assoc()){
?>
<tr>
<td><?php echo $rowcd['id'] ?> </td>
<td align="center"><?php echo $rowcd['well_no'] ?></td>
<td align="center"><?php echo $rowcd['well_name'] ?></td>
<td colspan="5">
<table rules="all">
<tr>
<?php
$querycd = "select * from cd where pidd=".$rowcd['id'];
$resultcd = $mysqli->query($querycd);
while($rowcd = $resultcd->fetch_assoc()){
?>
<td width="100" align="center"><?php echo $rowcd['cd_no'] ?></td>
<td colspan="4">
<table rules="all">
<tr>
<?php
$queryl = "select * from lib_cd_logs where pid=".$rowcd['cd_no'];
$resultl = $mysqli->query($queryl);
while($rowl = $resultl->fetch_assoc()){
?>
<td width="155"><?php echo $rowl['logs'] ?></td>
<td width="105" align="center"><?php echo $rowl['bottom'] ?></td>
<td width="100" align="center"><?php echo $rowl['top'] ?></td>
<td width="100" align="right"><?php echo $rowl['date'] ?></td>
</tr>
<?php
}
?>
</table>
</td>
</tr>
<?php
}
?>
</table>
</td>
<?php
}
}
?>
</tr>
</table>
I hope this is what you meant as per your data table shown above
<div>
<table border="1">
<thead>
<tr ><th >Select</th>
<th>Well_Number</th>
<th>Well_Name</th>
<th>CD No:</th>
<th >Logs</th>
</tr>
</thead>
<tr>
<td>id</td>
<td>well</td>
<td>name</td>
<td>
<table border="1" width="100%">
<tr>
<td>1</td>
</tr>
<tr>
<td>2</td>
</tr>
</table>
</td>
<td>
<table border="1" width="100%">
<tr>
<td>Log1</td>
</tr>
<tr>
<td>Log2</td>
</tr>
</table>
</td>
</tr>
</table>
</div>
I have a problem i want to put the $message inside the table that is a equivalent as a "Search not found".
Here is my picture outside the table $message = Search not found
View:
<div class="z table-responsive" >
<table class=" table table-hover" >
<thead >
<tr >
<th>ID Number</th>
<th>First name</th>
<th>Middle name</th>
<th>Last name</th>
<th>Sex</th>
</tr>
</thead>
<?php if ( isset($message) ){
echo $message;
} else{ foreach($results as $row){
?>
<tbody>
<tr>
<td><?php echo $row-> Idnumber ?></td>
<td class="text-capitalize "><?php echo $row -> Firstname ?></td>
<td class="text-capitalize"><?php echo $row->Middlename ?></td>
<td class="text-capitalize"><?php echo $row-> Lastname ?></td>
<td class="text-capitalize"><?php echo $row-> Sex?></td>
<td>
Option
</td>
</tr>
</tbody>
<?php }} ?>
</tbody>
</table>
</div>
You are using wrong end tags.
This will print Search not found inside the table with colspan 5 and center aligned
Note: Most of time we check where foreach value is empty ($results). But in your case you are checking some thing else ($message).
Changes
<tr> <!-- Changed -->
<td colspan="5" align="center"><?php echo $message; ?> </td>
</tr>
if ( isset($message) ){ is changed to if (!empty($message)){
Final code
<div class="z table-responsive" >
<table class=" table table-hover" >
<thead >
<tr >
<th>ID Number</th>
<th>First name</th>
<th>Middle name</th>
<th>Last name</th>
<th>Sex</th>
</tr>
</thead>
<tbody>
<?php
if (!empty($message)) # improved
{
?>
<tr> # Changed
<td colspan="5" align="center"><?php echo $message; ?> </td>
</tr>
<?php
}
else
{
foreach($results as $row)
{
?>
<tr>
<td><?php echo $row-> Idnumber ?></td>
<td class="text-capitalize "><?php echo $row -> Firstname ?></td>
<td class="text-capitalize"><?php echo $row->Middlename ?></td>
<td class="text-capitalize"><?php echo $row-> Lastname ?></td>
<td class="text-capitalize"><?php echo $row-> Sex?></td>
<td>
<a href="<?php echo site_url('viewstudentinalpha/viewspecific/'.$row->Id) ?>" class="btn btn-info " style="font-size: 18px;" type="submit" name="submit" role="button">
Option
</a>
</td>
</tr>
<?php
}
}
?>
</tbody>
</table>
</div>
Edit 01
In Controller
function search_keyword()
{
$session_data = $this->session->userdata('logged_in');
$data['Username'] = $session_data['Username'];
$keyword = $this->input->post('keyword');
$data['results'] = $this->model_adminlogin->search($keyword);
$this->load->view('result_view',$data);
}
In View
Alter your if like this.
Copy all codes i have added in above for your view. and only change this few lines.
<?php
if (!empty($results)) # Change
{
?>
<tr> # Change
<td colspan="5" align="center"> Search not found </td> # Change
</tr>
<?php
}
else
{
This isn't an issue with CodeIgniter so much as your code. What you are trying to do with the code is to put the message between the <thead> and <tbody>, and not in any table tags.
This is the same as trying to put it between rows in a table, and therefore gets interpreted as not being part of the table, and drawn outside of the table as a result.
If you put the message into the <tbody>, it will go in the right place, so you can do:
<?php if ( isset($message) ){
echo "<tbody><tr><td colspan='5'>" . $message . "</td></tr></tbody>";
}....
try this
<tbody>
<?php
if ( isset($result )
// or if (!isset($message)) //depend on your code
{
foreach($results as $row){
?>
<tr>
<td><?php echo $row-> Idnumber ?></td>
<td class="text-capitalize "><?php echo $row -> Firstname ?></td>
<td class="text-capitalize"><?php echo $row->Middlename ?></td>
<td class="text-capitalize"><?php echo $row-> Lastname ?></td>
<td class="text-capitalize"><?php echo $row-> Sex?></td>
<td>
Option
</td>
</tr>
<?php }}
else
//or elseif(isset($message)) //depend on your code
{
echo $message; ?>
}
</tbody>
</table>
</div>
i need to fill a table with mysql data, but i want to add a new line for every 3 mysql records.
filling the table its easy. but how do i tell to add a <tr> to every 3 records??
so far i have this:
<table width="30%" border="0">
<tbody>
<tr>
<?php if($totalRows_rsSdk>0){
do{
?>
<td align="center" valign="middle"><input type="checkbox" class="css-checkbox" name="sdkcheck" id="sdkcheck<?php echo $row_rsSdk['id']; ?>"/><label for="sdkcheck<?php echo $row_rsSdk['id']; ?>" class="css-label2 radGroup3"><?php echo $row_rsSdk['nome']; ?></label></td>
<td align="center" valign="middle"><img src="Images/sdk-icons/<?php echo $row_rsSdk['icon']; ?>" height="70"></td>
<?php } while ($row_rsSdk = mysql_fetch_assoc($rsSdk));} ?>
</tr>
</tbody>
</table>
Try this code:
<table width="30%" border="0">
<tbody>
<tr>
<?php if($totalRows_rsSdk>0){
$counter = 0;
do{
?>
<td align="center" valign="middle"><input type="checkbox" class="css-checkbox" name="sdkcheck" id="sdkcheck<?php echo $row_rsSdk['id']; ?>"/><label for="sdkcheck<?php echo $row_rsSdk['id']; ?>" class="css-label2 radGroup3"><?php echo $row_rsSdk['nome']; ?></label></td>
<td align="center" valign="middle"><img src="Images/sdk-icons/<?php echo $row_rsSdk['icon']; ?>" height="70"></td>
<?php
$blockSize = 3;
$counter++;
if ($counter >= $blockSize) {
$counter = 0;
?>
</tr>
<tr>
<?php
}
} while ($row_rsSdk = mysql_fetch_assoc($rsSdk));} ?>
<?php echo str_repeat('<td></td>',($blockSize-$counter)); ?>
</tr>
</tbody>
</table>
I have the following php/html code :
<div id="demo">
<table cellpadding="0" cellspacing="0" border="0" class="display" id="example">
<thead>
<tr>
<th>Medicine Name</th>
<th>Batch Number</th>
<th>Total Quantity</th>
<th>Expiry Date(s)</th>
<th>Selling Price</th>
<th> Total Price</th>
<th>Issue</th>
</tr>
</thead>
<tbody>
<?php foreach ($prescription as $prescribed): ?>
<tr class="odd gradeX">
<td><?php echo $prescribed['commodity_name']; ?></td>
<td ><?php echo $prescribed['batch_no']; ?></td>
<td><?php echo $prescribed['total_quantity']; ?></td>
<td><?php echo $prescribed['expiry_date']; ?></td>
<td ><?php echo $prescribed['selling_price']; ?></td>
<td><?php
$total_quantity = $prescribed['total_quantity'];
$selling_price = $prescribed['selling_price'];
$total_quantity_float = floatval($total_quantity);
$selling_price_float = floatval($selling_price);
$total_price = $total_quantity_float*$selling_price_float;
echo $total_price;
?></td>
<td>
<a class="issue" href="#types" id="issue">Issue</a>
<input type="hidden" name="batch_no" id="batch_no" value="<?php echo $prescribed['batch_no']; ?>"/>
</td>
<!-- <td> <a id="issue1" class="issue1" href="#types">Issue</a> </td>-->
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
I would like to get the total sum of the total_price variable which is displayed(total_price variable) as a row on the table. This should show the total price for all the commodities, how can I do this best?
try this
<?php
$total_price_sum = 0;
foreach ($prescription as $prescribed){
..
..
$total_price_sum = $total_price_sum + $total_price;
}
echo $total_price_sum;
?>
You can do this by adding to a variable each time you loop. This can be done as follows:
<?php
$grand_total = 0;
foreach ($prescription as $prescribed){
?>
..... all the HTML bits .....
<?
$grand_total = $grand_total + $total_price;
}
echo $grand_total;
?>
Hope that helps.
Regards,
Ralfe
is this a good way of doing it? or should i use a date time stamp with seconds rather?
while i am on a page, the new message must come through without me refreshing the page
my code is written in php:
<div id='div_longgray_gradient2'>
<div id='div_float_img'>
<table width='96%' border='0'>
<tr>
<td rowspan='2' width='40px' align='left'>
<img src='/images/rainbow/arrow.png'>
</td>
<td align='left'>
<span class='spn_big_black_rbc'>MESSAGES</span>
</td>
</tr>
<tr>
<td align='left'>
<span class='spn_med_lightblue_rbc'>Inbox</span>
</td>
<td align='left'>
</td>
</tr>
</table>
<br/>
<br/>
<table width='80%' align='center'>
<tr>
<td class='td_show_contact_heading' align='left'><span class='spn_med_lightblue_rbc'>Received</span></td>
<td class='td_show_contact_heading' align='left'><span class='spn_med_lightblue_rbc'>Message</span></td>
<td class='td_show_contact_heading' align='left'><span class='spn_med_lightblue_rbc'>From</span></td>
</tr>
<?php
$cursor = $pager->getFirstIndice();
foreach ($pager->getResults() as $msg)
{
$has_freechat = false;
//changed id to withid here
$freechat_req_link="profiles/confirmfreechat?withid=".$msg->getRcProfileTableRelatedByProfileIdFrom()->getId();
$freechat_req_link=link_to('Freechat',$freechat_req_link,'class=link_small_dark');
$cc = sizeof ($fc_records);
for($i = 0; $i < $cc; $i++)
{
if($fc_records[$i]->getProfileIdWith() == $msg->getProfileIdFrom())
{
$has_freechat = true;
break;
}
}
$unique_code_from = $msg->getRcProfileTableRelatedByProfileIdFrom()->getUniqueCode();
$block_url = link_to('Block User',"blocklist/block?unqiue_code=$unique_code_from",'class=link_medium_blue');
echo "<tr>";
$date = add_date($msg->getCreatedAt(),$hr=2);
echo "<td class='td_show_contact_item' align='left'>".$date."</td>";
$opened_once = $msg->getOpenedOnce();
if($opened_once >= 1)
{
echo "<td class='td_show_contact_item' align='left'>".link_to($msg->getSubject(), 'messagebox/read?cursor='.$cursor,'class=link_medium_blue')."</td>";
}
else
{ ?>
<td align='left'>
<a href="<?php echo url_for('messagebox/read?cursor=').$cursor ?>" style='color:#ff0000 !important' class='spn_small_red_rbc'><?php echo $msg->getSubject();?></a>
</td>
<?php
}
echo "<td class='td_show_contact_item' align='left'>".$unique_code_from." ( $block_url )</td>";
echo "</tr>";
++$cursor;
}
function add_date($givendate,$hr=2)
{
$cd = strtotime($givendate);
$newdate = date('Y-m-d H:i:s', mktime(date('h',$cd)+$hr, date('i',$cd), date('s',$cd), date('m',$cd), date('d',$cd), date('Y',$cd)));
return $newdate;
}
?>
</table>
<br/>
Displaying results <?php echo $pager->getFirstIndice() ?> to <?php echo $pager->getLastIndice() ?>.
<br/>
<?php if ($pager->haveToPaginate()): ?>
<?php echo link_to('«', 'messagebox/list?page='.$pager->getFirstPage()) ?>
<?php echo link_to('<', 'messagebox/list?page='.$pager->getPreviousPage()) ?>
<?php $links = $pager->getLinks(); foreach ($links as $page): ?>
<?php echo ($page == $pager->getPage()) ? $page : link_to($page, 'messagebox/list?page='.$page) ?>
<?php if ($page != $pager->getCurrentMaxLink()): ?> - <?php endif ?>
<?php endforeach ?>
<?php echo link_to('>', 'messagebox/list?page='.$pager->getNextPage()) ?>
<?php echo link_to('»', 'messagebox/list?page='.$pager->getLastPage()) ?>
<?php endif ?>
<table width='96%' border='0'>
<tr>
<td rowspan='2' width='40px' align='left'>
<img src='/images/rainbow/arrow.png'>
</td>
<td align='left'>
<span class='spn_big_black_rbc'></span>
</td>
</tr>
<tr>
<td align='left'>
<span class='spn_med_lightblue_rbc'>Sent Items</span>
</td>
</tr>
</table>
<br/>
<br/>
<table width='80%' align='center'>
<tr>
<td class='td_show_contact_heading' align='left'><span class='spn_med_lightblue_rbc'>Sent</span></td>
<td class='td_show_contact_heading' align='left'><span class='spn_med_lightblue_rbc'>Message</span></td>
<td class='td_show_contact_heading' align='left'><span class='spn_med_lightblue_rbc'>To</span></td>
</tr>
<?php
$cursor2 = $pager2->getFirstIndice();
$br = sizeof ($block_records);
foreach ($pager2->getResults() as $item)
{
$link = link_to('Delete',"messagebox/deleteSentmsg?mid=".$item->getId(),'class=link_medium_blue');
$id = $item->getRcProfileTableRelatedByProfileIdTo()->getId();
?>
<tr>
<td class='td_show_contact_item' width='15%' align='left'><?php echo $date = add_date($item->getCreatedAt(),$hr=2); ?></td>
<td class='td_show_contact_item' width='45%' align='left'><?php echo $item->getMessage()?></td>
<td class='td_show_contact_item' width='25%' align='left'><?php echo $item->getRcProfileTableRelatedByProfileIdTo()->getUniqueCode()." ".$link;?></td>
</tr>
<?php
++$cursor2;
}
?>
</table>
<br/>
Displaying results <?php echo $pager2->getFirstIndice(); ?> to <?php echo $pager2->getLastIndice(); ?>.
<br/>
<?php if ($pager2->haveToPaginate()): ?>
<?php echo link_to('«', 'messagebox/list?page2='.$pager2->getFirstPage(),'class=link_big_dark') ?>
<?php echo link_to('<', 'messagebox/list?page2='.$pager2->getPreviousPage(),'class=link_big_dark') ?>
<?php $links = $pager2->getLinks(); foreach ($links as $page2): ?>
<?php echo ($page2 == $pager2->getPage()) ? $page2 : link_to($page2, 'messagebox/list?page2='.$page2,'class=link_big_dark') ?>
<?php if ($page2 != $pager2->getCurrentMaxLink()): ?> - <?php endif ?>
<?php endforeach ?>
<?php echo link_to('>', 'messagebox/list?page2='.$pager2->getNextPage(),'class=link_big_dark') ?>
<?php echo link_to('»', 'messagebox/list?page2='.$pager2->getLastPage(),'class=link_big_dark') ?>
<?php endif ?>
</div>
</div>
can anyone give some advise please?
i have no ajax/JS here so dont know how i would incorporate it
PHP is a server side language and will not update a page once it has been fetched by the browser. To do this you will need to use a combination of server side and client side scripts.
One way of making your page update it's content is to use AJAX (http://api.jquery.com/jQuery.ajax/) combined with a timer (setInterval() and setTimeout()) to query a PHP script and check for updates every x seconds. The updates can then be added to the page when they are available using JavaScript / jQuery.