You are here: Re: writing records to text file « PHP SQL « IT news, forums, messages
Re: writing records to text file

Posted by Ian Davies on 10/26/05 22:24

Thanks Nick
Those function were exactly what Ive been searching for but to no avail.
One thing about implode can you limit how many of the fields it returns
I ask because I have modified this
implode(',', $nt)
to
implode("', '", $nt)
because I want quotes around some of the text (as the file will be used to
insert records, mostly text into an mysql table)
However some of the fields are numbers so they do not need quotes so your
original script
implode(',', $nt)
would work

Is there an easy way to do this without lots of code? Doesnt matter if there
isnt as I understand its ok (even desirable) to put numbers in quotes too.

Ian

"NC" <nc@iname.com> wrote in message
news:1130352471.018033.296450@o13g2000cwo.googlegroups.com...
> Ian Davies wrote:
> >
> > I have the following code which displays some some formatted
> > text in my browser. The problem is I need to create a text file
> > and write the records from this array into it.
>
> Shouldn't be too difficult...
>
> $query = "select * from Questions";
> $rt = mysql_query($query)
> or die(mysql_error());
> $fp = fopen('mydata.txt', 'w')
> or die('Could not open the text file for writing');
> while ($nt = mysql_fetch_array($rt, MYSQL_NUM)){
> $line = "INSERT INTO tQuestions VALUES (" .
> implode(',', $nt) .
> ");\r\n";
> fwrite($fp, $line);
> }
> fclose($fp);
>
> Cheers,
> NC
>

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация