问题描述:

This is my PHP code for creating excel files. Even though the excel is creating but the data is not returned from the database table.

<?php

$dbhost = "localhost";

$dbuser = "MY DATABASE USERNAME";

$dbpass = "MY DATABASE PASSWORD";

function dbConnect($db="") { global $dbhost, $dbuser, $dbpass;

$dbcnx = @mysql_connect($dbhost, $dbuser, $dbpass)

or die("The site database appears to be down.");

if ($db!="" and [email protected]_select_db($db))

die("The site database is unavailable.");

return $dbcnx;

}

require_once 'excel_files/Spreadsheet/Excel/Writer.php';

$workbook = new Spreadsheet_Excel_Writer();

$format_bold =& $workbook->addFormat();

$format_bold->setBold();

$worksheet =& $workbook->addWorksheet();

$worksheet->write(0, 0, "Sl.No", $format_bold);

$worksheet->write(0, 1, "Employee's Name", $format_bold);

$worksheet->write(0, 2, "Net pay for the month", $format_bold);

$worksheet->write(0, 3, "Account Number", $format_bold);

//$worksheet->write(0, 4, "comments", $format_bold);

# start by opening a query string

$fullquery="select * from payroll";

$result=mysql_db_query($dbuser,$fullquery);

$i=1;

while($row=mysql_fetch_assoc($result)){

$worksheet->write($i, 0, "$row[sl_no]");

$worksheet->write($i, 1, "$row[employee_name]");

$worksheet->write($i, 2, "$row[salary]");

$worksheet->write($i, 3, "$row[account_no]");

//$worksheet->write($i, 4, "$row[comments]");

$i++;

}

$workbook->send('test.xls');

$workbook->close();

?>

相关阅读:
Top