I am looking to write a MySQL query to a csv file.
At the minute I:
check for the original file, and delete it;
create a new (blank) file;
run the MySQL query and pass it into an array;
write it to the new file;
But it is missing something, as it only writes the first line from the query.
my code so far is:
Code: <?php
//Delete Original File
...
//Set variables
$uName = "root";
$pWord = "password";
$host = "localhost";
$Query = "[i]...MySQL query...[/i]";
$Filename = str_replace('.php', '', basename("Report")) . '_' . date("Ymdhis") . '.csv';
$ReportFiles = "c:ReportFiles\";
$Newfile = $ReportFiles.$Filename;
$cr = "n";
//Create a new (empty) file
echo exec("<nul (set/p z=) > "$Newfile"");
//Run MySQL Query
$connection = mysql_connect($host, $uName, $pWord) ;
mysql_select_db("dbName", $connection) ;
$result = mysql_query ($Query, $connection);
while ($row = mysql_fetch_array($result, MYSQL_NUM))
$String = implode(",",$row);
{
//Open file and save contents of query to that file
$fp = fopen($Newfile,"a");
if($fp){
fwrite($fp,$String.$cr);
fclose($fp);
echo "File saved successfully";
} else {
echo "Error saving file!";
}
}
?>
Gerenate tabel in Php
I whant to generate a tabel takeing data from database like this one so the results to be display on 2 columns<table width="50%" border="0" cellspacing="0"
rdns with php
I am trying to build a script that will show all of the different domains that are hosted on the same ip. However when I do a rdns lookup with php only 1 of the domains is returned. How can I make it
I need help with formatting date from mysql! with php!
Hello guys*Note: this is a php question not MySQL question, please do not move it to mysql section! Thank you.anyway, I have a record from the database as 2009-12-31 23:59:59I needed to when ever I
PHP not creating file.
Its supposed to create a .ini file in the /scriptfiles/users/ with the name they entered into the field then its supposed to create a password in the file in md5 encryption like this
PHP Mysql Staff Induction System
Hi there, I'm pretty new to PHP and Mysql so could really do with being pointed in the right direction with this problem I have.I am trying to set up a system induct new members of staff onto their
php call servlet
I have done a php backup application .So there is a form that user pick some files to zip and download.Because of a problem with greek characters I make a servet (java) to create the zip.But I want
phpMailer will not connect using SMTP
I am trying to use phpMailer with smtp:Code: [Select]$mailer = new PHPMailer();$mailer->IsSMTP();$mailer->Mailer = "smtp";$mailer->SMTPSecure = 'tls';
limitations on array_unique()
Does any one know what/how imitations are applied to array_unique? I have an issue where no matter how big (as in over this limit) the array is array_unique always returns an array with 32768
Web Application Recipe
Hi Guys! I am working with the Web Application recipes. I am currently working on the send password page. The page is working, but I sends the same password and username regardless of the email
Help with forum quoting?
Hi im working on a forum and I have alomost finished it but i want a user quote system like twitter and facebook with the @ sign to start it off, however even though im good at php coding and have