PDA

View Full Version : Creating 2 csv files - how to


pmaonline
05-18-2005, 05:37 PM
hi i have this code to export clients from a database table to a csv file and it work good, but this db has 100 000 clients and i need to separate the file in two csv files. My code is this :

<?php
if (!$HTTP_GET_VARS['submit'])
{
?>
<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//DE">
<html <?php echo HTML_PARAMS; ?>>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=<?php echo CHARSET; ?>">
<title><?php echo TITLE; ?></title>
<link rel="stylesheet" type="text/css" href="includes/stylesheet.css">
</head>
<body marginwidth="0" marginheight="0" topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0" bgcolor="#CCCC33">

<table border="0" width="100%" cellspacing="2" cellpadding="2" >
<tr>
<td width="<?php echo BOX_WIDTH; ?>" valign="top"><table border="0" width="<?php echo BOX_WIDTH; ?>" cellspacing="1" cellpadding="1" class="columnLeft">
</table></td><td>


<?php
echo "<center><font face=verdana size=2>Export clients</font>
<br>
<br>";
echo '<form action="'. $phpself.'">';
echo '<input type="submit" value="Export clients" name="submit">
</form>';

?>

</td>
</table>
<center><font color="#666666" size="2"></font></center>
<br>
</body>
</html>
<?php

}

else

{
$end_of_line = chr(10).chr(13);
$fim_file = "[END]";

$contents5=$end_of_file; //final de ficheiro

$contents1="primeiro nome;ultimo nome;contribuinte;codigo cliente;email;morada;freguesia;codigo postal;localidade;telefone;newsletter;password;xxx\n";

$user_query = mysql_query('select c.*, adb.* from customers as c left join address_book as adb on c.customers_id = adb.customers_id');

while($row = mysql_fetch_array($user_query))

{
$contents.=$row[customers_firstname].";";
$contents.=$row[customers_lastname].";";
$contents.=$row[entry_NIF].";";
$contents.=$row[customers_id].";";
$contents.=$row[customers_email_address].";";
$contents.=$row[entry_street_address].";";
$contents.=$row[entry_suburb].";";
$contents.=$row[entry_postcode].";";
$contents.=$row[entry_city].";";
$contents.=$row[customers_telephone].";";
$contents.=$row[customers_newsletter].";";
$contents.=$end_of_line;

}
Header("Content-Disposition: attachment; filename=clients_exp.csv");

print $contents;
print $contents5;
}

?>