PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old September 16th, 2004, 04:42 PM
CeCi CeCi is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Posts: 11 CeCi User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 6 m 33 sec
Reputation Power: 0
Writing Data into a .TXT or .DAT file

hi,

I need to grab data from a MySQL datatabse and save/write it to a .DAT or .TXT file. It can be Tab Delimited.
The data has to be saved in the following manner:
PHP Code:
 Column1        Column2
1hr               data1
2hrs             data2
3hrs             data3
4hrs             data4
.....
N-nrs 

So, two columns and tab delimited.
If you have any idead please let me know.

-C

Reply With Quote
  #2  
Old September 20th, 2004, 12:14 PM
MadCowDzz's Avatar
MadCowDzz MadCowDzz is offline
I'm Internet Famous
Dev Articles Frequenter (2500 - 2999 posts)
 
Join Date: Jan 2003
Location: Toronto, Canada
Posts: 2,890 MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Week 16 h 14 m 9 sec
Reputation Power: 8
Do you have any code? Or is this a school assignment?

Reply With Quote
  #3  
Old September 20th, 2004, 01:37 PM
CeCi CeCi is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Posts: 11 CeCi User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 6 m 33 sec
Reputation Power: 0
UPDATE: I just solved my own problem. Thank you!

Ok. I was able to grab data from the database and save it to a .txt file.

My problem is that I only want 'X' number of fields, say two fields. It has to be TAB Delimited, which it now works but It refused to break at the end of the line.
PHP Code:
while ($rows mysql_fetch_array($result)){ 
            
$fields mysql_num_fields($result)or die('error on line: '.__LINE__.' '.mysql_error());
            
$content ""
            
//calc the length of the line (number of elements) 
                
for($i 0$i $fields$i++){ 
             if (
$fields == 2) {
                 
$content $content $rows[$i]."\t""\n";
             }
                }
//next 
 
         
$content substr($content0strlen($content)-2). "\n"//remove the last pipe as its not needed and adds the new line character 
 
             // Write $content to our opened file. 
             
if (fwrite($handle$content) === FALSE) { 
                 echo 
"Cannot write to file ($filename)"
                 exit; 
             } 
            }
//end while 


OUTPUT: 'john marry jessica carol james julie jeff'.

DESIRED OUTPUT:
john marry
jessica carol
james julie
jeff

What am i doing wrong?

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingPHP Development > Writing Data into a .TXT or .DAT file


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
Stay green...Green IT