0

I have a script having three columns:

  • id
  • name
  • amount

It is fetching data from two queries. I want to download the data displayed in the html table into the xls format using php. I am trying to implement a download script but i am missing something, here is my download code script. It consists of a complete page where data is displayed in the html tabe and after that it asks for download.

<table border="2">

<thead>

    <tr>
        <th>Member ID</th>
        <th>Member Name</th>
        <th>Amount</th>
        

    </tr>
<?php
include('db.php');

//header to give the order to the browser
header('Content-Type: text/csv');
header('Content-Disposition: attachment;filename=exported-data.csv');

$d_f   = "2014-11-01";
$d_to  = "2015-01-05";
$fid   = "PNQ001";

//select table to export the data
$select_table=mysql_query("select member.id,login.name from member inner join login on member.id=login.id where member.f_id='$fid' order by member.id");
$rows = mysql_fetch_assoc($select_table);

//if ($rows)
//{
//getcsv(array_keys($rows));
//}
while($rows)
{
//getcsv($rows);
$rows = mysql_fetch_assoc($select_table);

?>


    <tr>
        <td class="center"><?php echo $rows['id'];?></td>
        <td><?php echo ucfirst($rows['name']);?></td>
        <td>
        <?php 
        
        $mid   = $rows['id'];
        $CountMoney=mysql_query("select * from details where f_id='$fid' and m_id='$mid' and date between '$d_f' and '$d_to'");
        $rows1 = mysql_fetch_assoc($CountMoney);
        $point = mysql_query("select plan.amount,plan.name from plan inner join member on member.plan_code=plan.id where member.id='$mid'");
        $get_points  = mysql_fetch_array($point);
        $totals=0;
        while($row2=  mysql_fetch_assoc($CountMoney))
        {
            $totals= $row2['a_mail']+$totals;
        }
        echo $totals*$get_points['amount'];

        
        ?>
        </td>
       


    </tr>



<?php
}

// get total number of fields present in the database
//function getcsv($no_of_field_names)
//{
//$separate = '';
//
//
//// do the action for all field names as field name
//foreach ($no_of_field_names as $field_name)
//{
//if (preg_match('/\\r|\\n|,|"/', $field_name))
//{
//$field_name = '' . str_replace('', $field_name) . '';
//}
//echo $separate . $field_name;
//
////sepearte with the comma
//$separate = ',';
//}
//
////make new row and line
//echo "\r\n";
//}
?>
</tbody>
</table>
Henk Jansen
  • 1,142
  • 8
  • 27

0 Answers0