Hi all,
I'm currently using a sql to csv script.
Here is the part i'm currently working on:
if (($go) && ($sql2csv)) {
mysql_pconnect($db_host, $user_nm, $password) or die( "Unable to connect to SQL server");
@mysql_select_db($database) or die( "Unable to select database");
if($table == 'approved'){
$sqlcont = "select * from company_details,contact_details,mailing_address,key_personnel,payment_details,company_categories WHERE type_email = 'accepted' AND client_update='yes'";
} else if($table == 'payment_details'){
$sqlcont = "select * from payment_details";
}
$result = mysql_query($sqlcont);
echo mysql_error();
function make_csv_happy($string,$seperator) {
$string = trim($string);
if (eregi("\$seperator",$string)) {
$string = ereg_replace("\"", "\"\"", $string);
$string = "\"".$string."\"";
}
$string = ereg_replace(10, "", $string);
$string = ereg_replace("\r", "", $string);
return $string;
}
if (mysql_fieldname($result, 0) == "id") $first_field = "iD";
while($col < mysql_numfields($result)) {
$fname = mysql_fieldname($result, $col);
if ($col < mysql_numfields($result)-1)$comma = $seperator;
else $comma = "";
if (($col == 0) && ($first_field))
$names .= $first_field.$comma;
else
$names .= make_csv_happy(strtoupper($fname),$seperator).$comma;
$col++;
}
$final = $names."\n";
while($row < mysql_numrows($result)) {
$col=0;
$line = "";
while($col < mysql_numfields($result)) {
$fname = mysql_fieldname($result, $col);
if ($col < mysql_numfields($result)-1)$comma = $seperator;
else $comma = "";
$line .= make_csv_happy(mysql_result($result,$row,$fname),$seperator).$comma;
$col++;
}
$final .= $line."\n";
$row++;
}
if ($send) {
header("Content-disposition: filename=$table.csv");
header("Content-type: application/octetstream");
header("Pragma: no-cache");
header("Expires: 0");
$client=getenv("HTTP_USER_AGENT");
if (ereg('[^(]*\((.*)\)[^)]*',$client,$regs)) {
$os = $regs[1];
if (eregi("Win",$os)) $crlf="\r\n";
}
} else {
echo "</center><p align=\"left\"><pre>";
}
echo $final;
if (!$send) echo "</pre></p>";
}
?>
At the moment if this line is executed:
if($table == 'payment_details'){
$sqlcont = "select * from payment_details";
it works fine but if the other condition is met:
if($table == 'approved'){
$sqlcont = "select * from company_details,contact_details,mailing_address,key_personnel,payment_details,company_categories WHERE company_details.type_email = 'accepted' AND company_details.client_update='yes'";
the page timesout and i get this error message:
PHP Fatal error: Maximum execution time of 45 seconds exceeded in /s101/home4/infoquorum/admin/download.php on line 198
The line where it timesout is:
$result = mysql_query($sqlcont);
echo mysql_error();
Can anyone tell me how to achieve multiple sql to csv table downloads on one csv file or will i have to do one download for each table?
Any ideas greatly apprciated.
Cheers,
micmac