Implementing Copy Excel CSV PDF button in PHP

Implementing Copy Excel CSV PDF button in PHP

DavidMukoroDavidMukoro Posts: 2Questions: 1Answers: 0

Please, I am pretty new to this forum and I find the above plugin will be useful for my project. I like to know how I can implement the Copy Excel CSV Pdf export buttons in my php script. Below is the code for assistance.

<link rel="stylesheet" type="text/css" href="DataTables-1.10.9/media/css/jquery.dataTables.css">
 <!-- jQuery -->
<script type="text/javascript" charset="utf8" src="DataTables-1.10.9/media/js/jquery.js"></script>
 <!-- DataTables -->
<script type="text/javascript" charset="utf8" src="DataTables-1.10.9/media/js/jquery.dataTables.js"></script>

<script type="text/javascript">
$(document).ready(function() {
    $("#custrec").DataTable();
    $("select.recs").change(function(){
       var selectedRec = $(".recClass option:selected").val();
       $.ajax({type: "POST",url:"process-rec.php",data:{recNo:selectedRec}}).done(function(data){
           $("#sub").html(data);
       });});});
</script>
<table width="100%" border="1" class="table table-striped" id="custrec" cellpadding="0">
<thead>
<tr>
<th colspan="10"><h3 align="right" style="color:red"> You are currently logon as :&nbsp;<?php echo $_SESSION["role"];?></h3></th>
</tr>
  <tr><th colspan="19"><h2> Customer Information Record</h2><button type="button" class="prtBtn btn btn-success" onclick="window.print()">Print</button></th></tr>
   <tr>
    <th nowrap="nowrap">S/NO </th>
    <th nowrap="nowrap">Customer ID</th>
    <th nowrap="nowrap">Group ID</th>
    <th nowrap="nowrap">Customer Location</th>
    <th nowrap="nowrap">Surname</th>
    <th nowrap="nowrap">Firstname</th>
    <th nowrap="nowrap">Othername</th>
    <th nowrap="nowrap">Sex</th>
    <th nowrap="nowrap">Home Address</th>
    <th nowrap="nowrap">Email Address</th>
    <th nowrap="nowrap">Mobile</th>
    <th nowrap="nowrap">Passport</th>
    <th nowrap="nowrap">Kin's Name</th>
    <th nowrap="nowrap">Kin's Address</th>
    <th nowrap="nowrap">Kin's Mobile</th>
    <th nowrap="nowrap">Guarantor's Name</th>
    <th nowrap="nowrap">Guarantor's Address</th>
    <th nowrap="nowrap">Guarantor's Mobile</th>
    <th nowrap="nowrap">Guarantor's Passport</th>
  </tr></thead>
 <tbody>
$getInfo2 = mysqli_query($connection,"SELECT * FROM tab_customer WHERE custloc ='".$_SESSION['location']."'ORDER BY custid ");  
while($rw = mysqli_fetch_array($getInfo2)){
    $c++; ?>
   <tr>
   <td nowrap='nowrap'><?php echo $c;?></td>
   <td nowrap='nowrap'><?php echo $rw['custid']?></td>
   <td nowrap='nowrap'><?php echo $rw['grpid'];?></td>
   <td nowrap='nowrap'><?php echo $rw["custloc"];?></td>
   <td nowrap='nowrap'><?php echo $rw['surname'];?></td>
   <td nowrap='nowrap'><?php echo $rw['firstname'];?></td>
   <td nowrap='nowrap'><?php echo $rw['othername'];?></td>
   <td nowrap='nowrap'><?php echo $rw['sex'];?></td>
   <td nowrap='nowrap'><?php echo $rw['homeadd'];?></td>
   <td nowrap='nowrap'><?php echo $rw['emailadd'];?></td>
   <td nowrap='nowrap'><?php echo $rw['mobile'];?></td>
   <td nowrap='nowrap'><img src="<?php echo $rw['custpass'];?>"height="50" width="100" /></td>
   <td nowrap='nowrap'><?php echo $rw["kinname"];?></td>
   <td nowrap='nowrap'><?php echo $rw["kinadd"];?></td>
   <td nowrap='nowrap'><?php echo $rw["kinmobile"];?></td>
   <td nowrap='nowrap'><?php echo $rw["guarantorname"];?></td>
   <td nowrap='nowrap'><?php echo $rw["guarantoradd"];?></td>
   <td nowrap='nowrap'><?php echo $rw["guarantormobile"];?></td>
   <td nowrap='nowrap'><img src="<?php echo $rw['guarantorpass'];?>"height='50' width='100'/></td>
   </tr>
 <?php  };?>
</tbody>
</table>

Answers

  • allanallan Posts: 62,312Questions: 1Answers: 10,225 Site admin

    As in your want the PHP to create the CSV, PDF, etc files? You'd need to write the code to do that - that is not something that this project provides.

    Allan

  • DavidMukoroDavidMukoro Posts: 2Questions: 1Answers: 0

    @allan: If you check the sample table on this site. You will see that the you can perform all the requested on the sample data. I also want to do the same with my code above. how can i do that .

  • allanallan Posts: 62,312Questions: 1Answers: 10,225 Site admin

    You mean you want to create the PDF etc on the client-side like in my examples? In which case, you would just use the code like in those examples.

    If you have tried to use that code and haven't been successful, please link to the page you are having problems with so we can help debug it.

    Allan

  • jLinuxjLinux Posts: 981Questions: 73Answers: 75

    All you have to do, is basically copy and paste the code from the Example, its pretty basic... Has the CSS and JS right there, and even the files to include

This discussion has been closed.