How to redesign a table when there isn't some data - javascript

I have a table that shows some data from database. I want if there isn't data in some <td> , the column from next row, to be displayed in its place. This is what I mean:
If I have this kind of table:
When there is no data for example for $data['created_at'], it should be displayed $data['due_date'] in its place.
How could I do that?
<table>
<tr>
<td colspan="3">
<?php if(!empty($data['created_at'])){ ?>
<strong><?php echo "Created Date:";?>:</strong> <?php echo $data['created_at']; ?>
<?php } ?>
</td>
<td colspan="3">
<?php if(!empty($data['username'])){ ?>
<strong><?php echo "Username:";?>:</strong> <?php echo $data['username']; ?>
<?php } ?>
</td>
</tr>
<tr>
<td colspan="3">
<?php if(!empty($data['due_date'])){ ?>
<strong><?php echo "Date delivery:";?>:</strong> <?php echo $data['due_date']; ?>
<?php } ?>
</td>
<td colspan="3">
<?php if(!empty($data['copmany'])){ ?>
<strong><?php echo "Company:";?>:</strong> <?php echo $data['copmany']; ?>
<?php } ?>
</td>
</tr>
</table>

Are you looking to just omit a row if the result is empty? Simply change the place of your if statement to encompass the td
<table>
<tr>
<?php if(!empty($data['created_at'])){ ?>
<td colspan="3">
<strong><?php echo "Created Date:";?>:</strong> <?php echo $data['created_at']; ?>
</td>
<?php } ?>
<?php if(!empty($data['username'])){ ?>
<td colspan="3">
<strong><?php echo "Username:";?>:</strong> <?php echo $data['username']; ?>
</td>
<?php } ?>
</tr>
<tr>
<?php if(!empty($data['due_date'])){ ?>
<td colspan="3">
<strong><?php echo "Date delivery:";?>:</strong> <?php echo $data['due_date']; ?>
</td>
<?php } ?>
<?php if(!empty($data['copmany'])){ ?>
<td colspan="3">
<strong><?php echo "Company:";?>:</strong> <?php echo $data['copmany']; ?>
</td>
<?php } ?>
</tr>
</table>

Related

I am trying to delete a row of data using a check box, when I click on delete my php should delete the row

I have a Dynamic table that has a checkbox on each row. When I click on the check box and then click on my delete button I would like the action to go to my php and delete the row that has a marked checkbox.
I have tried the solution here: Delete selected row from table in php but this did not work for me. I keep getting an error stating that " checkbox is an undefined index"
<?php
if (isset($_POST['delete'])){
$Tasknumber_delete = $_POST['checkbox'];
mysqli_query($link,"Delete from Universe.Task where TaskNumber = $Tasknumber_delete");
}
?>
<form class="searchBar" method="post" action=''>
<input type="submit" action='POST' class="btn-group" id="delete" name="delete" value="delete" style="background-color: #757575; font-family: HelveticaNeue;font-size: 13px;">
</form
table class="taskTable" >
<tbody class="task-tbody">
<?php while($row1 = mysqli_fetch_array($Table)){ $task123=$row1[2];?>
<!-- removed onclick= -->
<tr class = "task-tr" onclick="myFunction('<?php echo $task123;?>')">
<td class="task-td"><input type="checkbox" name="checkbox" value="<?php echo $task123?>"></td>
<td class="task-td"> <?php if ($row1[0]=='backlog') {$statuscss= 'statusBacklog';} elseif ($row1[0]== 'inprogress') {$statuscss= 'statusInProgress';} else{ $statuscss= 'statusDone';} echo '<div class="',$statuscss,'">';?><?php echo $row1[0];?></div></td>
<td class="task-td"> <?php if ($row1[1]=='HIGH') {$statuscss= 'priorityHigh';} elseif ($row1[1]== 'MEDIUM') {$statuscss= 'priorityMedium ';} else{ $statuscss= 'priorityLow';} echo '<div class="',$statuscss,'">';?> <?php echo $row1[1];?></div></td>
<td class="task-td" > <?php echo $task123;?></td>
<td class="task-description"> <?php echo $row1[3];?></td>
<td class="task-td"> <?php echo $row1[4];?></td>
<td class="task-td"> <?php echo $row1[5];?></td>
<td class="task-td" width="15"> </td>
</tr>
<?php }?>
</tbody>
</table>
I added the code for the delete php, the form that has the delete button and my table where the check box is located.
Let's put the closed form-tag at the end of your script and name your checkbox : name="checkbox[]"
<form class="searchBar" method="post" action=''>
<input type="submit" action='POST' class="btn-group" id="delete" name="delete" value="delete" style="background-color: #757575; font-family: HelveticaNeue;font-size: 13px;">
<table class="taskTable" >
<tbody class="task-tbody">
<?php while($row1 = mysqli_fetch_array($Table)){ $task123=$row1[2];?>
<!-- removed onclick= -->
<tr class = "task-tr" onclick="myFunction('<?php echo($task123); ?>')">
<td class="task-td"><input type="checkbox" name="checkbox[]" value="<?php echo $task123?>"/></td>
<td class="task-td"> <?php if ($row1[0]=='backlog') {$statuscss= 'statusBacklog';} elseif ($row1[0]== 'inprogress') {$statuscss= 'statusInProgress';} else{ $statuscss= 'statusDone';} echo '<div class="',$statuscss,'">';?><?php echo $row1[0];?></div></td>
<td class="task-td"> <?php if ($row1[1]=='HIGH') {$statuscss= 'priorityHigh';} elseif ($row1[1]== 'MEDIUM') {$statuscss= 'priorityMedium ';} else{ $statuscss= 'priorityLow';} echo '<div class="',$statuscss,'">';?> <?php echo $row1[1];?></div></td>
<td class="task-td" > <?php echo $task123;?></td>
<td class="task-description"> <?php echo $row1[3];?></td>
<td class="task-td"> <?php echo $row1[4];?></td>
<td class="task-td"> <?php echo $row1[5];?></td>
<td class="task-td" width="15"> </td>
</tr>
<?php }?>
</tbody>
</table>
</form>

Bootstrap Modal & MySQL Query using PHP

I am trying to have mysql data displayed on a bootstrap modal and for some reason it is only pulling the ID of the first link that is clicked and not the ID for the row specified on the link clicked to display said modal. (hope that makes sense).
The link to be clicked:
<a data-toggle="modal" data-target="#leadModal" href="?id=<?php echo $id; ?>"><?php echo $f; echo ' '; echo $l; ?></a>
Here is the code that surrounds the link:
<div class="table-responsive">
<table class="table table-bordered" id="dataTable" width="100%" cellspacing="0">
<thead>
<tr>
<th>Name</th>
<th>Email Address</th>
<th>Primary Phone</th>
<th>Date Created</th>
<th>Arrival Date</th>
<th>Departure Date</th>
</tr>
</thead>
<tfoot>
<tr>
<th>Name</th>
<th>E-Mail Address</th>
<th>Primary Phone</th>
<th>Date Created</th>
<th>Arrival Date</th>
<th>Departure Date</th>
</tr>
</tfoot>
<tbody>
<?php
$agent = $userRow['userName'];
$query = "SELECT * FROM leads WHERE status='Follow-Up' && agent='$agent'";
$result = mysql_query($query) or die(mysql_error());
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
$f = $line['first'];
$l = $line['last'];
$e = $line['email'];
$p1 = $line['PrimePhone1'];
$p2 = $line['PrimePhone2'];
$p3 = $line['PrimePhone3'];
$a = $line['arrival'];
$d = $line['departure'];
$ag = $line['agent'];
$id = $line['id'];
$dc = $line['datecreated'];
$es = $line['emailsent'];
?>
<tr>
<td><a data-toggle="modal" data-target="#leadModal" href="?id=<?php echo $id; ?>"><?php echo $f; echo ' '; echo $l; ?></a></td>
<td><?php echo $e; ?></td>
<td><?php echo $p1; echo '-'; echo $p2; echo'-'; echo $p3; ?></td>
<td><?php echo $dc; ?></td>
<td><?php echo $a; ?></td>
<td><?php echo $d; ?></td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
</div>
And here is what I have for code to display the data in the modal:
<!-- Lead Modal-->
<div class="modal fade" id="leadModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header"><?php
$id = $_GET["id"];
$query = "SELECT * FROM leads WHERE id=$id";
$result = mysql_query($query);
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) { ?>
<h5 class="modal-title" id="exampleModalLabel"><?php echo $line['first']; ?> <?php echo $line['last']; ?>'s Existing Lead</h5><?php } ?>
<button class="close" type="button" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body"><?php
$id = $_GET["id"];
$query = "SELECT * FROM leads WHERE id=$id";
$result = mysql_query($query) or die(mysql_error());
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
?>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr align="center">
<td>
<table width="750" border="2" align="center" cellpadding="1" cellspacing="0" class="table">
<tr>
<td>Original Agent:</td>
<td><?php echo $line['agent']; ?></td>
</tr>
<?php if ($line['upagent'] == ''){ } else { ?> <tr>
<td>Last Updated By:</td>
<td><?php echo $line['upagent']; ?></td>
</tr><?php } ?>
<tr>
<td width="186">First Name:</td>
<td width="552">
<?php echo $line['first']; ?></td>
</tr>
<?php if ($line['last'] == ''){ } else { ?> <tr>
<td>Last Name:</td>
<td><?php echo $line['last']; ?></td>
</tr><?php } ?>
<?php if ($line['email'] == ''){ } else { ?><tr>
<td>E-Mail Address:</td>
<td><?php echo $line['email']; ?></td>
</tr><?php } ?>
<tr>
<td>Primary Phone:</td>
<td><?php echo $line['PrimePhone1']; echo '-'; echo $line['PrimePhone2']; echo '-'; echo $line['PrimePhone3']; ?></td>
</tr>
<?php if ($line['AltPhone1'] == '' || $line['AltPhone2'] == '' || $line['AltPhone3'] == '') { } else { ?>
<tr>
<td>Alternate Phone:</td>
<td><?php echo $line['AltPhone1']; echo '-'; echo $line['AltPhone2']; echo '-'; echo $line['AltPhone3']; ?></td>
</tr>
<?php } ?>
<tr>
<td>Lead Created:</td>
<td><?php echo $line['datecreated']; ?></td>
</tr>
<?php if($line['emailsent'] == 1){ ?> <tr>
<td>Follow-Up Email Sent:</td>
<td><?php echo $line['followupsent']; ?></td>
</tr>
<?php } ?>
<tr>
<td>Arrival Date:</td>
<td><?php echo $line['arrival']; ?></td>
</tr>
<tr>
<td>Departure Date:</td>
<td><?php echo $line['departure']; ?></td>
</tr>
<?php if ($line['adults'] == ''){ } else { ?>
<tr>
<td>Adults:</td>
<td><?php echo $line['adults']; ?></td>
</tr><?php } ?>
<?php if ($line['child'] == ''){ } else { ?>
<tr>
<td>Children:</td>
<td><?php echo $line['child']; ?></td>
</tr>
<?php } ?>
<?php if ($line['area'] == ''){ } else { ?>
<tr>
<td>Requested Area:</td>
<td><?php echo $line['area']; ?></td>
</tr>
<?php } ?>
<?php if ($line['budget'] == ''){ } else { ?>
<tr>
<td>Budget:</td>
<td><?php echo $line['budget']; ?></td>
</tr>
<?php } ?>
<?php if ($line['suggested'] == ''){ } else { ?>
<tr>
<td>Suggested Properties:</td>
<td><?php echo $line['suggested']; ?></td>
</tr>
<?php } ?>
<?php if ($line['discount'] == ''){ } else { ?>
<tr>
<td>Discount Offered:</td>
<td><?php echo $line['discount']; ?></td>
</tr>
<?php } ?>
<?php if ($line['promo'] == ''){ } else { ?>
<tr>
<td>Promo Code:</td>
<td><?php echo $line['promo']; ?></td>
</tr>
<?php } ?>
<tr>
<td>Lead Status:</td>
<td><?php echo $line['status']; ?></td>
</tr>
<?php if ($line['notes'] == ''){ } else { ?>
<tr>
<td height="85">Additional Notes:</td>
<td><?php echo $line['notes']; ?></td>
</tr>
<?php } ?>
<?php if ($line['resnum'] == ''){ } else { ?>
<tr>
<td>Reservation Number:</td>
<td><?php echo $line['resnum']; ?></td>
</tr><?php } } ?>
</table>
</td>
</tr>
</table>
</div>
<div class="modal-footer">
<button class="btn btn-secondary" type="button" data-dismiss="modal">Close</button>
<a class="btn btn-primary" href="#">Button</a>
</div>
</div>
</div>
</div>
Any help is greatly appreciated.
Thanks,
Scott
What you're asking cannot be done in the current design. Your answer will be in looping your db results to create several modals (messy) or using AJAX to retrieve the modal data based on the link ID. A good example is in the answer here: Using Jquery Ajax to retrieve data from Mysql

PHP submit button while loop

Hi guys im having a bit of a problem on how to get the value of the table row everytime i click an add button. what im trying to achieve is that to pass the value of the row to another php file for sql query. at the moment i have a table using a while loop and displaying a list of names from the database with a "ADD" button per row. When ever i click the add button regardless of which row i always get the value of the last row. can someone please point of on which part of the code i made a mistake?
here is my code
<form action="addFriend.php" method="post"> <table class="table table-bordered">
<?php
$i = 1;
while($row = mysqli_fetch_array($records))
{
?>
<tr>
<td><?php echo $i; ?></td>
<td><input type="text" name="addedUser" value="<?php echo $row["username"]; ?>" readonly></td>
<td>
<button type="submit" name="row_<?php echo $i; ?>" id="row_user" value="<?php echo $row["username"]; ?>" class="btn btn-info">ADD</button>
<?php $i++; ?>
</td>
</tr>
<?php
}
?>
</table>
</form>
Try Below code. As you want only $row["username"] and it is already stored in button value. Add form in while loop and give same name for button so that you can get username in addFriend.php
<table class="table table-bordered">
<?php
$i = 1;
while($row = mysqli_fetch_array($records))
{
?>
<tr>
<td><?php echo $i; ?></td>
<td><input type="text" name="addedUser" value="<?php echo $row["username"]; ?>" readonly></td>
<td>
<form action="addFriend.php" method="post">
<button type="submit" name="row" id="row_user" value="<?php echo $row["username"]; ?>" class="btn btn-info">ADD</button>
</form>
<?php $i++; ?>
</td>
</tr>
<?php
}
?>
</table>
Now in addFriend.php you can get value by $_POST['row'];
Try Below script
<form action="addFriend.php" method="post"> <table class="table table-bordered">
<?php
$i = 1;
while($row = mysqli_fetch_array($records))
{
?>
<tr>
<td><?php echo $i; ?></td>
<td><input type="text" name="**addedUser[]**" value="<?php echo $row["username"]; ?>" readonly></td>
<td>
<button type="submit" name="row_<?php echo $i; ?>" id="row_user" value="<?php echo $row["username"]; ?>" class="btn btn-info">ADD</button>
<?php $i++; ?>
</td>
</tr>
<?php
}
?>
</table>
</form>
In addFriend.php
print form data using print_r($_REQUEST);

javascript unkown error on css code line

I have this html table:
<center><input type="button" value="Print last visit report" id="printpagebutton" onclick="printData()"/>
<input type="button" value="Print all reports" id="printpagebutton2" onclick="printData1()"/>
</center></BR>
<center></center>
<div class=WordSection1 id="mydiv1">
<?php while($rows = mysqli_fetch_array($result)) { $data2 =$rows['echo_files'];
$dataFile2 = str_replace('/', '\\', $data2); ?>
<div id="mydiv">
<form action="/clinic form/update/update.php" id="Form2" method="post">
<table border="1" align="center" id="table">
<tr align="center">
<th colspan="3" bgcolor="#7a7878">DR. Omar GHNEIM - Patient Medical History</th>
</tr>
<tr align="center">
<th colspan="3"><?php echo 'Medical History of '.$rows['name']?></th>
</tr>
<tr>
<th>Medicaments</th>
<th>Illness</th>
<th>Echo Results</th>
</tr>
<tr>
<?php if(!empty($rows['remarcs']) && trim($rows['remarcs'])!=''):?>
<td width="250px"><?php echo $rows['remarcs'] ?></td>
<?php else: ?>
<td width="250px" align="center">Not Available</td>
<?php endif; ?>
<?php if(!empty($rows['illness']) && trim($rows['illness'])!=''):?>
<td width="250px"><?php echo $rows['illness'] ?></td>
<?php else: ?>
<td width="250px" align="center">Not Available</td>
<?php endif; ?>
<?php if(!empty($rows['echo']) && trim($rows['echo'])!=''):?>
<td width="250px"><?php echo $rows['echo'] ?></td>
<?php else: ?>
<td width="250px" align="center">Not Available</td>
<?php endif; ?>
</tr>
<tr>
<th>Clinic Test Result</th>
<th>Habbits</th>
<th>Allergy</th>
</tr>
<tr>
<?php if(!empty($rows['test_res']) && trim($rows['test_res'])!=''):?>
<td width="250px"><?php echo $rows['test_res'] ?></td>
<?php else: ?>
<td width="250px" align="center">Not Available</td>
<?php endif; ?>
<?php if(!empty($rows['habbits']) && trim($rows['habbits'])!=''):?>
<td width="250px"><?php echo $rows['habbits'] ?></td>
<?php else: ?>
<td width="250px" align="center">Not Available</td>
<?php endif; ?>
<?php if(!empty($rows['allergy']) && trim($rows['allergy'])!=''):?>
<td width="250px"><?php echo $rows['allergy'] ?></td>
<?php else: ?>
<td width="250px" align="center">Not Available</td>
<?php endif; ?>
</tr>
<tr>
<th>Occupation</th>
<th>PMHx</th>
<th>PSHx</th>
</tr>
<tr>
<?php if(!empty($rows['occup']) && trim($rows['occup'])!=''):?>
<td width="250px"><?php echo $rows['occup'] ?></td>
<?php else: ?>
<td width="250px" align="center">Not Available</td>
<?php endif; ?>
<?php if(!empty($rows['pmhx']) && trim($rows['pmhx'])!=''):?>
<td width="250px"><?php echo $rows['pmhx'] ?></td>
<?php else: ?>
<td width="250px" align="center">Not Available</td>
<?php endif; ?>
<?php if(!empty($rows['pshx']) && trim($rows['pshx'])!=''):?>
<td width="250px"><?php echo $rows['pshx'] ?></td>
<?php else: ?>
<td width="250px" align="center">Not Available</td>
<?php endif; ?>
</tr>
<tr>
<th colspan="3">Echo Files</th>
</tr>
<tr>
<?php if(!empty($data2) && trim($data2)!=''):?>
<td colspan="3" align="center"><center><a href='download_PopUp.php?data=<?php echo $dataFile2; ?>'>Echo Test files exist</a></center></td>
<?php else: ?>
<td colspan="3" align="center"><center>No echo files</center></td>
<?php endif;?>
</tr>
<tr>
<th>P.E</th>
<?php if(!empty($rows['pe']) && trim($rows['pe'])!=''):?>
<td width="250px"><?php echo $rows['pe'] ?></td>
<?php else: ?>
<td width="250px" align="center">Not Available</td>
<?php endif; ?>
<th rowspan="4" align="left">Signature</th>
</tr>
<tr>
<th>Date</th><td><?php echo $rows['date'] ?></td>
</tr>
<tr>
<th>Address of Patient</th><td><?php echo $rows['address'] ?></td>
</tr>
<tr>
<th>Phone Number of patient</th><td><?php echo $rows['phone_num'] ?></td>
</tr>
</table>
And this javascript file to print a div in a page with a css, but dreamweaver software give an error:
function printData()
{
var divToPrint=document.getElementById("mydiv");
newWin= window.open("");
newWin.document.write(divToPrint.outerHTML);
var css =`table, td, th {
border: 1px solid black;
text-align:justify;
}
th {
background-color: #7a7878;
text-align:center
}`;
var div = $("<div />", {
html: '­<style>' + css + '</style>'
}).appendTo( newWin.document.body);
newWin.print();
newWin.close();
}
$('button').on('click',function(){
printData();
});
But in the browser when I hit F12, nothing is given as error, and the css style won't work.
Template strings are not supported in IE. That's probably why dreamweaver throws an error on that line.
Either escape newlines:
var myString = 'some \n\
multiline \n\
string';
Or concatenate lines:
var myString = 'some \n' +
'multiline \n' +
'string';
A multiline string in javascript can be made like that in most modern browsers but does not work in IE and older browsers.
You should change
var css =`table, td, th {
border: 1px solid black;
text-align:justify;
}
th {
background-color: #7a7878;
text-align:center
}`;
to:
var css = "table, td, th { \n\
border: 1px solid black; \n\
text-align:justify; \n\
} \n\
\n\
th { \n\
background-color: #7a7878; \n\
text-align:center \n\
}";
It is even better to make it:
var css = "table, td, th { \n"+
" border: 1px solid black; \n"+
" txt-align:justify; \n"+
"} \n"+
"th { \n"+
" background-color: #7a7878; \n"+
" text-align:center; \n"+
"}";
The reason that your css is not displayed is:
Once IE has processed all the styles loaded with the page, the only reliable way to add another stylesheet is with document.createStyleSheet(url)
See the MSDN article on createStyleSheet for a few more details.
edit
So in your case, you can add the above css code to table.css, upload it to your server. And at the moment you want to add the style, you use
document.createStyleSheet('http://yourserver.com/table.css');

JQUERY data tables installation

I want to use the datatables jquery plugin for my project. I'm doing the project on cakePHP. I can't seem to get datatables running. I'm not quite sure if my code is right. Also I have added the css file and the two JS files in my directory under Webroot/css and Webroot/js.
Can someone help me please?
My code is as follows:
<html>
<head>
<!-- DataTables CSS -->
<link rel="stylesheet" type="text/css" href="/DataTables-1.10.0/css/jquery.dataTables.css">
<!-- jQuery -->
<script type="text/javascript" charset="utf8" src="/DataTables-1.10.0/js/jquery.js"></script>
<!-- DataTables -->
<script type="text/javascript" charset="utf8" src="/DataTables-1.10.0/js/jquery.dataTables.js"></script>
$(document).ready( function () {
$('#callTable').DataTable();
} )
</head>
<?php
$usertype=$this->SESSION->read('User.usertype');
if($usertype=="admin")
echo $this->element('setTopNavigation');
else
echo $this->element('setTopNavigationStaff');
//var_dump($calls);
?>
<div class="callsIndex">
<h2><?php echo __('Call Details'); ?> </h2>
<div class="bottomButtonnew"><?php echo $this->Html->link(__('Add Calls'), array('action' => 'add')); ?></div>
<table id="callTable" cellpadding="0" cellspacing="0">
<tr>
<th><?php echo $this->Paginator->sort('Call Date'); ?></th>
<th><?php echo $this->Paginator->sort('Call Time'); ?></th>
<th><?php echo $this->Paginator->sort('Comments'); ?></th>
<th><?php echo $this->Paginator->sort('Next Call Date'); ?></th>
<th><?php echo $this->Paginator->sort('Customer Name'); ?></th>
<th><?php echo $this->Paginator->sort('Company Name'); ?></th>
<th><?php echo $this->Paginator->sort('Employee Name'); ?></th>
<th class="actions"><?php echo __(''); ?></th>
</tr>
<?php foreach ($calls as $call): ?>
<?php
$class ='';
if($call['Call']['next_call_date']==date('Y-m-d')){
$class = ' class="call_for_today"';
}
?>
<tr<?php echo $class; ?>>
<td><?php echo date("d-m-Y", strtotime($call['Call']['call_date'])); ?> </td>
<td><?php echo h($call['Call']['call_time']); ?> </td>
<td><?php echo h($call['Call']['comments']); ?> </td>
<td><?php echo date("d-m-Y", strtotime($call['Call']['next_call_date'])); ?> </td>
<td>
<?php echo $this->Html->link($call['Customers']['customer_name'], array('controller' => 'customers', 'action' => 'view', $call['Customers']['id'])); ?>
</td>
<td>
<?php echo $this->Html->link($call['Companies']['company_name'], array('controller' => 'companies', 'action' => 'view', $call['Companies']['id'])); ?>
</td>
<td>
<?php echo $this->Html->link($call['Employees']['employee_name'], array('controller' => 'employees', 'action' => 'view', $call['Employees']['id'])); ?>
</td>
<td class="actions">
<?php echo $this->Html->link(__('View'), array('action' => 'view', $call['Call']['id'])); ?>
</td>
</tr>
<?php endforeach; ?>
</table>
<p>
<?php
echo $this->Paginator->counter(array(
'format' => __('Page {:page} of {:pages}, showing {:current} records out of {:count} total')
));
?> </p>
<div class="paging">
<?php
echo $this->Paginator->prev('< ' . __('previous'), array(), null, array('class' => 'prev disabled'));
echo $this->Paginator->numbers(array('separator' => ''));
echo $this->Paginator->next(__('next') . ' >', array(), null, array('class' => 'next disabled'));
?>
</div>
<br>
</div>
There are two problems with your code.
1) Add document.ready inside script tag and put semicolon (;) at the end of document.ready
<script>
$(document).ready( function () {
$('#callTable').DataTable();
} );
</script>
2) And datatable work with table structure which has header enclosed in <thead></thead> tag and row enclosed inside <tbody></tbody> like below
:
<table id="callTable" cellpadding="0" cellspacing="0">
<thead>
<tr>
<th><?php echo $this->Paginator->sort('Call Date'); ?></th>
<th><?php echo $this->Paginator->sort('Call Time'); ?></th>
<th><?php echo $this->Paginator->sort('Comments'); ?></th>
<th><?php echo $this->Paginator->sort('Next Call Date'); ?></th>
<th><?php echo $this->Paginator->sort('Customer Name'); ?></th>
<th><?php echo $this->Paginator->sort('Company Name'); ?></th>
<th><?php echo $this->Paginator->sort('Employee Name'); ?></th>
<th class="actions"><?php echo __(''); ?></th>
</tr>
</thead>
<tbody>
<?php foreach ($calls as $call): ?>
<?php
$class ='';
if($call['Call']['next_call_date']==date('Y-m-d')){
$class = ' class="call_for_today"';
}
?>
<tr<?php echo $class; ?>>
<td><?php echo date("d-m-Y", strtotime($call['Call']['call_date'])); ?> </td>
<td><?php echo h($call['Call']['call_time']); ?> </td>
<td><?php echo h($call['Call']['comments']); ?> </td>
<td><?php echo date("d-m-Y", strtotime($call['Call']['next_call_date'])); ?> </td>
<td>
<?php echo $this->Html->link($call['Customers']['customer_name'], array('controller' => 'customers', 'action' => 'view', $call['Customers']['id'])); ?>
</td>
<td>
<?php echo $this->Html->link($call['Companies']['company_name'], array('controller' => 'companies', 'action' => 'view', $call['Companies']['id'])); ?>
</td>
<td>
<?php echo $this->Html->link($call['Employees']['employee_name'], array('controller' => 'employees', 'action' => 'view', $call['Employees']['id'])); ?>
</td>
<td class="actions">
<?php echo $this->Html->link(__('View'), array('action' => 'view', $call['Call']['id'])); ?>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
Your $(document).ready handler needs to be placed inside a <script> tag

Categories