Welcome to WebmasterWorld Guest from 54.226.143.14

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Write to file

Write items from DB on a separate line

   
6:51 pm on Dec 4, 2005 (gmt 0)

10+ Year Member



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.

6:55 pm on Dec 4, 2005 (gmt 0)

10+ Year Member



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.

5:25 pm on Dec 5, 2005 (gmt 0)

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



Yes, you do ;)

Strings [php.net]

 

Featured Threads

Hot Threads This Week

Hot Threads This Month