RE: array issue

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Good point and nice find, Jeff!

I wasn't sure where he was going with the data.. was he trying to save
the actual array, intact, for say a chaching exercise or did he want to
insert the contents of that array into a file?

Could go either way I suppose :)

Aaron

P.S. Working on a Sunday too?

> -----Original Message-----
> From: jeffrey_n_Dyke@Keane.com [mailto:jeffrey_n_Dyke@Keane.com]
> Sent: August 17, 2003 11:48 AM
> To: Aaron Wolski
> Cc: 'PHP-DB'; 'OpenSource'
> Subject: RE:  array issue
> 
> 
> This may or may not make sense for your issue.  but if you have the
whole
> array in memory you can serialize()  it and write the string that the
> function returns to the file.
> 
> $fp = fopen("yourfilename.txt", "w");
> $my_array_s = serialize($my_array);
> if (isset($fp)) {
>       fwrite($fp, $my_array_s);
> }
> 
> //to get it back into the same array as it was written, use
> $fp_cache = fopen("yourfilename.txt", "r") or die("can't open file");
> $fp_readc = fread($fp_cache, filesize("yourfilename.txt");
> $my_array_new = unserialize($fp_readc);
> 
> the data is exactly as it was returned from the db after you looped
> through
> the record set.
> 
> another idea. --http://www.php.net/manual/en/function.serialize.php
> hth
> jeff
> 
> 
> 
>                       "Aaron Wolski"
>                       <aaronjw@martekbi        To:
"'OpenSource'"
> <redhat@opensource.bz>, "'PHP-DB'" <php-db@lists.php.net>
>                       z.com>                   cc:
>                                                Subject:  RE: 
> array issue
>                       08/17/2003 11:33
>                       AM
> 
> 
> 
> 
> 
> 
> First, are you sure there is data in $my_array?
> 
> Add this after you set the array:
> 
> echo "<pre>"".print_r($my_array)."</pre>";
> 
> You'll need to loop through the array , writing each line in the file
at
> a time.
> 
> Something like:
> 
> //open the file stuff here
> foreach ($my_array AS $values)
> {
> 
>  fputs($fp, $value);
> 
> }
> //close the file stuff here
> 
> HTH
> 
> Aaron
> 
> > -----Original Message-----
> > From: OpenSource [mailto:redhat@opensource.bz]
> > Sent: August 17, 2003 11:31 AM
> > To: PHP-DB
> > Subject:  array issue
> > Importance: High
> >
> > hi ya'll
> >
> > I am having a nightmare on this issue of mine.
> > I've got this array that I need to write to a file...
> > :::::::: sample code below ::::::::
> >
> > while (something);
> > {
> > query data base
> >
> > $r_ul=ifx_fetch_row($sideQuery4);
> >
> > $type1 = array($rotation."\n");
> >
> > switch ($r_ul['number'])
> >    {
> >     case '4';
> >     $linea = $type1;
> >     break;
> >    }
> >
> > $final = $linea[0];
> >
> > $my_array = array();
> > array_push ($my_array, $final);
> >
> > }
> >
> > $file = 'db_dump.dat';
> > $fp = fopen($file, "w");
> > fputs($fp, $my_array); <--- I would like to write the complete array
> into
> > the file
> > fclose($fp);
> >
> > kindly assist with this issue..
> >
> > Thanks in advance
> 
> 
> 
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 
> 
> 
> 




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


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux