Hello
I need to create 2 csv files extracted out of data held in mysql database.
I have the code to create 1 csv file, but I am struggling to get this to loop round and create the 2nd file.
In terms of user functionality I want them to be able to create downloaded information files with one click off the website, and end up with 2 csv files.
code I have so far
//part 1
//CREATE RESULTS.CSV FILE
$query="SELECT `ConcesRef` FROM `tblUser` WHERE `ULogIn` = '$username'";
$result3 = mysql_query($query)
or die(mysql_error());
$row3 = mysql_fetch_array($result3);
$ConcesRef = $row3["ConcesRef"];
if ($ConcesRef)
{
header('Content-Type: application/download; name="DownloadedFromWebsite_Results.csv"');
header('Content-Disposition:attachment; filename="DownloadedFromWebsite_Results.csv"');
header('Content-Transfer-Encoding: binary');
require_once ('../mysql_connect.php'); //connect to the database
$List = array();
$count = 0;
if (sizeof($List) == 0)
{
//START FILLING IN THE FIELDNAME ON TOP OF EXCEL SHEET.
$fieldSql = "SHOW FIELDS FROM tblResults";
$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.
$query = "SELECT DateLogId FROM tblDateLog WHERE ConcesRef = $ConcesRef ORDER BY EndDate DESC LIMIT 1";
$result5 = mysql_query($query)
or die(mysql_error());
$row5 = mysql_fetch_array($result5);
$DateLogId = $row5["DateLogId"];
$sql = "SELECT * FROM tblResults WHERE ConcesRef = $ConcesRef";
$getInfo = mysql_query($sql);
while($row = mysql_fetch_array($getInfo, MYSQL_ASSOC))
{
while (list($key, $value) = each($row))
{
echo ("$value" . ",");
}
echo ("\n");
}
mysql_close();
}
else
{
listErrors();
}
}
else
{
echo "Not Able to Create Results File - Please Try Again";
}
// part 2
//CREATE DATELOG.CSV FILE
$query="SELECT `ConcesRef` FROM `tblUser` WHERE `ULogIn` = '$username'";
$result39 = mysql_query($query)
or die(mysql_error());
$row39 = mysql_fetch_array($result39);
$ConcesRef = $row39["ConcesRef"];
if ($ConcesRef)
{
header('Content-Type: application/download; name="DownloadedFromWebsite_Datelog.csv"');
header('Content-Disposition:attachment; filename="DownloadedFromWebsite_Datelog.csv"');
header('Content-Transfer-Encoding: binary');
require_once ('../mysql_connect.php'); //connect to the database
$List9 = array();
$count9 = 0;
if (sizeof($List9) == 0)
{
//START FILLING IN THE FIELDNAME ON TOP OF EXCEL SHEET.
$fieldSql9 = "SHOW FIELDS FROM tblDateLog";
$getFieldInfo9 = mysql_query($fieldSql9);
$i = 0;
while ($row9 = mysql_fetch_array($getFieldInfo9))
{
echo $row9['Field'] . ",";
}
echo ("\n");
//START FILLING IN THE ROWS IN EXCEL SHEET.
$sql9 = "SELECT * FROM tblDateLog WHERE ConcesRef = $ConcesRef";
$getInfo9 = mysql_query($sql9);
while($row99 = mysql_fetch_array($getInfo9, MYSQL_ASSOC))
{
while (list($key9, $value9) = each($row99))
{
echo ("$value9" . ",");
}
echo ("\n");
}
mysql_close();
}
else
{
listErrors();
}
}
else
{
echo "Not Able to Create DateLog File - Please Try Again";
}
?>
this code creates the first download file but then stops
Incidentally within the created csv file there is the text error message of 'No database selected' but I thought I had specified a connection to the database.
Any help is greatly appreciated
regards