homepage Welcome to WebmasterWorld Guest from 54.145.191.14
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Write to file
Write items from DB on a separate line
woldie

10+ Year Member



 
Msg#: 10999 posted 6:51 pm on Dec 4, 2005 (gmt 0)

Hi,

I'm creating a sites of the week functionality, and I'm having some trouble writing items from DB onto a separate line.

I've tried using \r and \n but that doesn't seem to work.

Any ideas?

$_file1 = 'site_of_the_week_1.txt';
$_fp1 = @fopen( $_file1, 'w' );

$site_of_week_1=mysql_query("select title,url
from db_links
where catid=$sub_catid
order by rand() limit 3");

while (list($DBtitle,$DBurl)=mysql_fetch_row($site_of_week_1))
{
$_text1 =$DBtitle.','.$DBurl.','.'\r\n';
@fwrite( $_fp1, $_text1 );
}

@fclose( $_fp1 );
$allfiles1 = file ("$base_url/site_of_the_week_1.txt");

Many Thanks

Woldie.

 

woldie

10+ Year Member



 
Msg#: 10999 posted 6:55 pm on Dec 4, 2005 (gmt 0)

Sorry, got it to work!

Here's the solution:

$_file1 = 'site_of_the_week_1.txt';
$_fp1 = @fopen( $_file1, 'w' );

$site_of_week_1=mysql_query("select title,url
from db_links
where catid=$sub_catid
order by rand() limit 3");

while (list($DBtitle,$DBurl)=mysql_fetch_row($site_of_week_1))
{
$_text1 =$DBtitle.','.$DBurl.','."\r\n";
@fwrite( $_fp1, $_text1 );
}

@fclose( $_fp1 );
$allfiles1 = file ("$base_url/site_of_the_week_1.txt");

Looks like you have to place \r\n in double quotes!

Woldie.

coopster

WebmasterWorld Administrator coopster us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 10999 posted 5:25 pm on Dec 5, 2005 (gmt 0)

Yes, you do ;)

Strings [php.net]

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved