Hello
I want to export 3 csv files each file containing data from a different table in the mysql database based on a constant variable.
Example;
I want to select all the information in the user table where the concession value is 1 and export it in csv file format, then look at another table, find where the concession value is 1 again and export that information into a seperate csv file.
I have this code;
session_start ();
$_SESSION['username'] = $username;
require_once ('../mysql_connect.php'); //connect to the database
//CREATE USER.CSV FILE
$result1 = mysql_query("SELECT ConcesRef FROM tblUser WHERE CLogIn = '$username'")
or die(mysql_error());
$ConcesRef = $result1;
if ($result1)
{
header('Content-Type: application/download; name="user_download.csv"');
header('Content-Disposition:attachment; filename="user_download.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 tblUser";
$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 tblUser 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 "need to pass QS values";
}
//CREATE DATELOG.CSV FILE
$result2 = mysql_query("SELECT ConcesRef FROM tblUser WHERE CLogIn = '$username'")
or die(mysql_error());
$ConcesRef = $result2;
if ($result2)
{
header('Content-Type: application/download; name="datelog_download.csv"');
header('Content-Disposition:attachment; filename="datelog_download.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 tblDateLog";
$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 tblDateLog 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 "need to pass QS values";
}
//CREATE RESULTS.CSV FILE
$result3 = mysql_query("SELECT ConcesRef FROM tblUser WHERE CLogIn = '$username'")
or die(mysql_error());
$ConcesRef = $result3;
if ($result3)
{
header('Content-Type: application/download; name="results_download.csv"');
header('Content-Disposition:attachment; filename="results_download.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.
$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 "need to pass QS values";
}
?>
It works in as much as it will create and export the first csv file, but doesn't do anything with the second and third csv files
Any ideas?
TIA