Sign in to follow this  
pinochio53

[web] Problems with creating files from php script. [Solved]

Recommended Posts

pinochio53    122
I have a php file that im using to create a txt file, i want to save the results from a mysql table in the file. I stuck in a loop that displays the data on the page. I wanted it to display the data, then write the content to the txt file. link to the file is http://www.4thleveldesigns.com/Warehouse/buffer.php. <?php require_once('Connections/warehouse.php'); ?> <?php mysql_select_db($database_warehouse, $warehouse); $query_Details = "SELECT * FROM Details"; $Details = mysql_query($query_Details, $warehouse) or die(mysql_error()); $row_Details = mysql_fetch_assoc($Details); $totalRows_Details = mysql_num_rows($Details); ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>Untitled Document</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <link href="style.css" rel="stylesheet" type="text/css"> </head> <body> <table border="1" class="Title_text"> <tr> <td>Serial</td> <td>TechName</td> <td>TechID</td> <td>JobNo</td> <td>Date</td> <td>Status</td> <td>ID</td> </tr><?php ?> <?php do { ?> <tr> <td><?php echo $row_Details['Serial']; ?></td> <td><?php echo $row_Details['TechName']; ?></td> <td><?php echo $row_Details['TechID']; ?></td> <td><?php echo $row_Details['JobNo']; ?></td> <td><?php echo $row_Details['Date']; ?></td> <td><?php echo $row_Details['Status']; ?></td> <td><?php echo $row_Details['ID']; ?></td> </tr> <? $fp = fopen( "TECH_BUFFER/TECH_BUFFER" & date("Y-m-d ")& "zzz.txt", "a" ); if(!$fp) { echo "Couldn't open the data file. Try again later."; exit; } $inputString = $row_Details['Serial'] +$row_Details['TechID'] + "\n"; fwrite( $fp, $inputString ); ?> <?php } while ($row_Details = mysql_fetch_assoc($Details)); ?> </table> <? fclose( $fp ); ?> </body> </html> <?php mysql_free_result($Details); ?> [Edited by - pinochio53 on March 30, 2006 11:24:49 PM]

Share this post


Link to post
Share on other sites
pinochio53    122
The problem is that it only writes one line unto the page.

'641699507676'<-- what it outputs to the file.

The webpage outputs just fine, it shows whats in the table, but that info doesnt go into the file, only that one line does.

Im expecting the Output to be like this:
'
001311BA4F8F 5105
XC9516DB0665 9950
XC9516DB0665 7676
001311BA4FEF 5243
'

Share this post


Link to post
Share on other sites
markr    1692
The thing which occurs to me, is it looks like you're using & for string concatenation:


$fp = fopen( "TECH_BUFFER/TECH_BUFFER" & date("Y-m-d ")& "zzz.txt", "a" );


This is probably not what you intended.

I don't know whether & does string concatenation in PHP - probably not. I think you must be confusing it with VB.

It's not creating a file called "0" somewhere, is it?

Mark

Share this post


Link to post
Share on other sites
pinochio53    122
come to think of it, i think it has, in the same directory where the buffer.php resides.

and it has at one time also created a file called 2006.

What i want this script to do is to create the text file with the file name TECH_BUFFER Ddmmyy hhmmss zzz.txt <-- meaning i want it to automatically add the date and time to the file name in that format. also i want to output to that file like this:

001311BA4F8F 5105
XC9516DB0665 9950
XC9516DB0665 7676
001311BA4FEF 5243

i want it to have that amount of space in between the values. I also want it to zip that txt file after its created. That is my ultimate goal with this script. some suggestions and help would be appreciated.

Share this post


Link to post
Share on other sites
pinochio53    122
Guys, i figured out the problem by myself, my problem was that i wasnt seperating my data into different strings. I was trying to put it in one big long string, which didnt really work, so i tried doing it as different string variables and then combining them in the fwrite statement, which worked :). Now i just have to figure out to have the script zip the txt file once its been created.

Share this post


Link to post
Share on other sites
pinochio53    122
Guys, i figured out the problem by myself, my problem was that i wasnt seperating my data into different strings. I was trying to put it in one big long string, which didnt really work, so i tried doing it as different string variables and then combining them in the fwrite statement, which worked :). Now i just have to figure out to have the script zip the txt file once its been created.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this