Re: [PHP-DB] fwrite(): can this function append to the middle of a file?

2007-08-16 Thread Chris

joefazee wrote:

Can i write to the middle of a file using the fwrite() function like

---
line one
line two
line three

and maybe the next day i want to write in between line two and line three.


Read in the whole file.

Put the line in the middle manually.

Write the whole file out again.

fwrite itself doesn't have the functionality you want.

--
Postgresql  php tutorials
http://www.designmagick.com/

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] fwrite()

2002-01-25 Thread daniel

 I'm trying to take the contents of a table and write them to a file on my
 server. Everything seems to function ok (AKA no errors) but no file gets
 written ... I can't figure out why. Can anyone shine some light on this dark
 problem?
 
   $db = mysql_connect(localhost,cloft,spring);
 
   mysql_select_db(countryloft);
 
   // get requests from table
   $result = mysql_query(SELECT * FROM catalogreq WHERE PROCESSED IS
 NULL);
 
   $fp = fopen($DOCUMENT_ROOT/catalogreq/catalogs.txt,w);
 
   fwrite($fp, $result);
 
   fclose($fp);
 
   $updatereq = mysql_query(UPDATE catalogreq SET PROCESSED = 'Y');
 
   echo Thank you!;
 
 
 Thanks for any help!

fwrite() needs a string as its second parameter. You are passing a
DB result index. Even if a file were being created, it would not
contain what you had hoped for. 

You will need to use $result with mysql_fetch_array() in order to
get any useful data out of it. However, that function will return
arrays of data, which you will need to massage into your deisred
format and issue it in the form of a string to fwrite().

Daniel J. Lashua


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




RE: [PHP-DB] fwrite()

2002-01-25 Thread Gurhan Ozen

You don't have anything to write to the file.. mysql_query() function
returns true or false, it doesn't return the actual qurey result you'd see
in mysql monitor. You have to use some other functions such as
mysql_fetch_array(), mysql_num_rows() to retrieve the data before you can
write it into a file.

Gurhan

-Original Message-
From: James Kupernik [mailto:[EMAIL PROTECTED]]
Sent: Friday, January 25, 2002 3:39 PM
To: [EMAIL PROTECTED]
Subject: [PHP-DB] fwrite()


I'm trying to take the contents of a table and write them to a file on my
server. Everything seems to function ok (AKA no errors) but no file gets
written ... I can't figure out why. Can anyone shine some light on this dark
problem?

  $db = mysql_connect(localhost,cloft,spring);

  mysql_select_db(countryloft);

  // get requests from table
  $result = mysql_query(SELECT * FROM catalogreq WHERE PROCESSED IS
NULL);

  $fp = fopen($DOCUMENT_ROOT/catalogreq/catalogs.txt,w);

  fwrite($fp, $result);

  fclose($fp);

  $updatereq = mysql_query(UPDATE catalogreq SET PROCESSED = 'Y');

  echo Thank you!;


Thanks for any help!



--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP-DB] fwrite()

2002-01-25 Thread James Kupernik

Still when I make the changes suggested the file will not be created, yet I
get no form of an error message.

Is there something else I'm missing?


 I'm trying to take the contents of a table and write them to a file on my
 server. Everything seems to function ok (AKA no errors) but no file gets
 written ... I can't figure out why. Can anyone shine some light on this
dark
 problem?

   $db = mysql_connect(localhost,cloft,spring);

   mysql_select_db(countryloft);

   // get requests from table
   $result = mysql_query(SELECT * FROM catalogreq WHERE PROCESSED
IS
 NULL);

   $fp = fopen($DOCUMENT_ROOT/catalogreq/catalogs.txt,w);

   fwrite($fp, $result);

   fclose($fp);

   $updatereq = mysql_query(UPDATE catalogreq SET PROCESSED =
'Y');

   echo Thank you!;


 Thanks for any help!

fwrite() needs a string as its second parameter. You are passing a
DB result index. Even if a file were being created, it would not
contain what you had hoped for.

You will need to use $result with mysql_fetch_array() in order to
get any useful data out of it. However, that function will return
arrays of data, which you will need to massage into your deisred
format and issue it in the form of a string to fwrite().

Daniel J. Lashua



-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP-DB] fwrite()

2002-01-25 Thread daniel

 Still when I make the changes suggested the file will not be created, yet I
 get no form of an error message.
 
 Is there something else I'm missing?

Please post your new code for review.


Daniel J. Lashua

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




RE: [PHP-DB] fwrite()

2002-01-25 Thread Jamie Kupernik

  $prefilename = date(m-d-y);

  $filename = $prefilename.txt;

  $db = mysql_connect(localhost,cloft,spring);

  mysql_select_db(countryloft);

  // get requests from table
  $result = mysql_query(SELECT * FROM catalogreq WHERE
PROCESSED IS NULL);

  $row = mysql_fetch_array($result);

  $fileresults = $row[0],$row[1]\n;

  $fp = fopen($DOCUMENT_ROOT/catalogreq/$filename,w);

  fwrite($fp, $fileresults);

  fclose($fp);

  $updatereq = mysql_query(UPDATE catalogreq SET PROCESSED =
'Y');

-Original Message-
From: daniel [mailto:[EMAIL PROTECTED]] 
Sent: Friday, January 25, 2002 4:15 PM
To: James Kupernik
Cc: [EMAIL PROTECTED]
Subject: Re: [PHP-DB] fwrite()


 Still when I make the changes suggested the file will not be created, 
 yet I get no form of an error message.
 
 Is there something else I'm missing?

Please post your new code for review.


Daniel J. Lashua



 
This message has been scanned for computer 
viruses and none were found. 

Country Curtains Information Systems Department 
 




 
This message has been scanned for computer 
viruses and none were found. 

Country Curtains Information Systems Department 
 



-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP-DB] fwrite()

2002-01-25 Thread daniel

   $prefilename = date(m-d-y);
 
   $filename = $prefilename.txt;
 
   $db = mysql_connect(localhost,cloft,spring);
 
   mysql_select_db(countryloft);
 
   // get requests from table
   $result = mysql_query(SELECT * FROM catalogreq WHERE
 PROCESSED IS NULL);
 
   $row = mysql_fetch_array($result);
 
   $fileresults = $row[0],$row[1]\n;
 
   $fp = fopen($DOCUMENT_ROOT/catalogreq/$filename,w);
 
   fwrite($fp, $fileresults);
 
   fclose($fp);
 
   $updatereq = mysql_query(UPDATE catalogreq SET PROCESSED =
 'Y');

Add if statements around your mysql calls to make sure they are
successful. For instance:

?

if(!($db = mysql_connect(localhost,cloft,spring))) {
  die(mysql_error() . \n);
}

?

Place such statements around mysql_query as well. Then... call
mysql_num_rows() on your $result to ensure that rows are being
returned. If all of those things check out okay... right before your
fwrite() statement try this:

?

print_r($row);

?

See if any data is print out on the screen.

If all of these fail, then chances are your error reporting
parameters are not set correctly and your file open/close commands
are generating errors. Check file permissions and actual interpreted
paths by printing the filenames out before you fopen() them, in the
same fashion that you issue them to fopen(). 


Let us know how it works out.

Daniel J. Lashua


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




RE: [PHP-DB] fwrite()

2002-01-25 Thread Gurhan Ozen

Jamie,
The main problem here is , you are selecting the rows that are some null
values. mysql_fetch* doesn't return any null columns. Yes, you read it
right, if you have a table with say, 5 columns and if 3 columns in a row are
null then you'll only have 2 columns that are not null .
  Make sure that this is not causing any problem for you.
  What does your table look like and and what values do your columns have
when processed is null anyway?

Gurhan


-Original Message-
From: Jamie Kupernik [mailto:[EMAIL PROTECTED]]
Sent: Friday, January 25, 2002 4:22 PM
To: 'daniel'
Cc: [EMAIL PROTECTED]
Subject: RE: [PHP-DB] fwrite()


  $prefilename = date(m-d-y);

  $filename = $prefilename.txt;

  $db = mysql_connect(localhost,cloft,spring);

  mysql_select_db(countryloft);

  // get requests from table
  $result = mysql_query(SELECT * FROM catalogreq WHERE
PROCESSED IS NULL);

  $row = mysql_fetch_array($result);

  $fileresults = $row[0],$row[1]\n;

  $fp = fopen($DOCUMENT_ROOT/catalogreq/$filename,w);

  fwrite($fp, $fileresults);

  fclose($fp);

  $updatereq = mysql_query(UPDATE catalogreq SET PROCESSED =
'Y');

-Original Message-
From: daniel [mailto:[EMAIL PROTECTED]]
Sent: Friday, January 25, 2002 4:15 PM
To: James Kupernik
Cc: [EMAIL PROTECTED]
Subject: Re: [PHP-DB] fwrite()


 Still when I make the changes suggested the file will not be created,
 yet I get no form of an error message.

 Is there something else I'm missing?

Please post your new code for review.


Daniel J. Lashua




This message has been scanned for computer
viruses and none were found.

Country Curtains Information Systems Department






This message has been scanned for computer
viruses and none were found.

Country Curtains Information Systems Department




--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]