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!";
}
}
?>
Storing Values taken from a DB...
Using this code it will generate a short list from my database <?phpmysql_connect('localhost','root','');mysql_select_db("clients");$fname = $_POST['firstname'];$SQL = "SELECT *
Big Problem!! Please help
Hi Guys,Im making a website for a friend have encountered a really annoying problem. When every i run the script below i get this error: "Parse error: syntax error, unexpected '}' in
Change Sort Order to Display Newest File First
Hi Guys,I have a page that sorts the contents (PDFs) of a directory and displays them on the webpage chronologically from the oldest (at top) to the newest (at bottom).I'd like to reverse this display
the problem with str_replace
$str="hahahahahahahahahahahahahaha";$nn=1;$str=str_replace('ha','MyGod',$str,$nn);echo $str;the result is MyGodMyGodMyGodMyGodMyGodMyGodMyGodMyGodMyGodMyGodMyGodMyGodMyGodMyGodWhy $nn has no
PHP doesn't send my mail
Hi all, I found this and used it to send mail. Simple contact form with some required fields. The validation works a bit but I don't get the mail HTML:some Javascript...Code: [Select]<form
Help If user voted, block them
On my Prayer request site, i let users Click a button to Pray for somone that has posted a pray, i got that all set up but.Code: // connect to db... if ($_GET['id']) { $id = (int) $_GET['id'];
Async WSAConnect failed on XP with error code = 2 ("File not found")
Hi all,
how to transport the Query and insfoset
Hi
How To Make More Than One Redirection with PHP on the same page?
Hey im trying to do a direction page where it open differently link direction pages every time somebody enter it.. like this for example any good hint on how to do this?<?phpheader(
SAP Logon Failed
I tried to login to SAP through MMC.