mat41
05-12-2004, 03:28 AM
PHPers
The below code is a working example of how I create a CSV file from a mySql table I have been trying to modify it to only include the fields I need, so far no luck, I would apreciate any ideas?
BTW:my database connection is in an include file ("scripts/auditdb.php")
containing:
------start include file contents-----------------
$conn = mysql_connect("localhost", "root", "admin") or die(mysql_error());
mysql_select_db("pdaAuditAlpha",$conn) or die(mysql_error());
------finish include file contents-----------------
<?
if ($_GET['branch'] != "")
{
header("Content-Disposition: attachment; filename=branch.csv");
include("scripts/auditdb.php");
$errorList = array();
$count = 0;
if (sizeof($errorList) == 0)
{
//START FILLING IN THE FIELDNAME ON TOP OF EXCEL SHEET.
$fieldSql = "SHOW FIELDS FROM sitedetails";
$getFieldInfo = mysql_query($fieldSql);
$i = 0;
while ($row = mysql_fetch_array($getFieldInfo))
{
echo $row['Field'] . ",";
}
echo ("\n");
//START FILLING IN THE ROWS IN EXCEL SHEET.
$sql = "SELECT * FROM sitedetails WHERE BSBCode = '".$_GET['bsb']."'";
$getInfo = mysql_query($sql);
while($row = mysql_fetch_array($getInfo, MYSQL_ASSOC))
{
while (list($key, $value) = each($row))
{
echo ("$value" . ",");
}
echo ("\n");
}
mysql_close($conn);
}
else
{
listErrors();
}
}
else
{
echo "need to pass QS values";
}
?>
Thanking you in advance
The below code is a working example of how I create a CSV file from a mySql table I have been trying to modify it to only include the fields I need, so far no luck, I would apreciate any ideas?
BTW:my database connection is in an include file ("scripts/auditdb.php")
containing:
------start include file contents-----------------
$conn = mysql_connect("localhost", "root", "admin") or die(mysql_error());
mysql_select_db("pdaAuditAlpha",$conn) or die(mysql_error());
------finish include file contents-----------------
<?
if ($_GET['branch'] != "")
{
header("Content-Disposition: attachment; filename=branch.csv");
include("scripts/auditdb.php");
$errorList = array();
$count = 0;
if (sizeof($errorList) == 0)
{
//START FILLING IN THE FIELDNAME ON TOP OF EXCEL SHEET.
$fieldSql = "SHOW FIELDS FROM sitedetails";
$getFieldInfo = mysql_query($fieldSql);
$i = 0;
while ($row = mysql_fetch_array($getFieldInfo))
{
echo $row['Field'] . ",";
}
echo ("\n");
//START FILLING IN THE ROWS IN EXCEL SHEET.
$sql = "SELECT * FROM sitedetails WHERE BSBCode = '".$_GET['bsb']."'";
$getInfo = mysql_query($sql);
while($row = mysql_fetch_array($getInfo, MYSQL_ASSOC))
{
while (list($key, $value) = each($row))
{
echo ("$value" . ",");
}
echo ("\n");
}
mysql_close($conn);
}
else
{
listErrors();
}
}
else
{
echo "need to pass QS values";
}
?>
Thanking you in advance