hi i've recently got this 2 functions from the internet that's suppose to convert any database query files to excel but the problem is i dont understand some of the lines can anyone please help me figure it out
here are the codes
function XLSFile($query, $file)
{
/*******************************************************
FUNCTION NAME:
XLSFile
AUTHOR:
bokeh
PURPOSE:
To create an Excel (.XLS) format file from any valid
database query.
DESCRIPTION:
bool XLSFile( string query, string file )
INPUTS:
$query (string) should be a valid MySQL query.
$file (string) is the file (including the path)to
which the Excel formatted data should be saved. A
database connection must exist before calling this
function.
RETURN VALUE:
Boolean, true on success, false otherwise.
*********************************************************/
$query_result = mysql_query($query) or
trigger_error("Function <b>RealXLSFile</b>: MySQL error, " . mysql_error(), E_USER_ERROR);
if(mysql_num_rows($query_result))
{
$fh = @fopen($file, 'w+') or
trigger_error('Function <b>RealXLSFile</b>: file could not be created (permissions problem).', E_USER_ERROR);
fwrite($fh, pack("ssssss", 0x809, 0x8, 0x0, 0x10, 0x0, 0x0));
$first_time = true;
$XLSrow = 0; $XLScol = 0;
while($row = mysql_fetch_assoc($query_result))
{
if($first_time)
{
$first_time = false;
$headings = array_keys($row);
foreach($headings as $heading)
{
fwrite($fh, pack("ssssss", 0x204, 8+($L = strlen($heading)), $XLSrow, $XLScol++, 0x0, $L).$heading);
}
}
$XLScol=0; ++$XLSrow;
foreach($headings as $heading)
{
if(is_numeric($row[$heading]))
{
fwrite($fh, pack("sssss", 0x203, 14, $XLSrow, $XLScol++, 0x0).pack("d", $row[$heading]));
}
else
{
fwrite($fh, pack("ssssss", 0x204, 8 + ($L = strlen($row[$heading])), $XLSrow, $XLScol++, 0x0, $L).$row[$heading]);
}
}
}
fwrite($fh, pack("ss", 0x0A, 0x00));
fclose($fh);
return true;
}
return false;
}
i guess my question is about the variable $file <-- it says i should include the path but what else do i include?? i think its only the path right?
[Mod Edit] - Added [php][/php] tags - bpat1434