Re: [PHP-DB] array issue

2007-11-27 Thread Jason Gerfen
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Clare Media wrote:
 Guys really in need of some assistance here.
 
 I am reading an xml file and want to loop through the entire file and
 display the information.
 
 Unfortunately I am only showing 1 item. how can I go about showing all news
 item?
 
 I've tried array and loop however I am not versed with any of them.
 
 Thanks in advance
 
  
 
  
 
 eg.
 
 -
 
 item
 
 titletitle 1/title
 
 descriptionDescription 1/description
 
 /item
 
 item
 
 titletitle 2/title
 
 descriptionDescription 2/description
 
 /item
 
 item
 
 titletitle 3/title
 
 descriptionDescription 3/description
 
 /item
 
 -
 
  
 
 My current code
 
 +
 
 function getNews() 
 
 {
 
 $file = NEWS_FILE..xml;

 if(!file_exists($file) || filemtime($file) 
 time() - 43200) {
 
 $this-data =
 @file_get_contents(http://feeds.mydomain.com/dailynews;);
 
 $fp = @fopen($file, 'w');
 
 @fwrite($fp, $this-data);
 
 @fclose($fd);
 
 }
 
 else $this-data =
 @file_get_contents($file);
 
 if(strlen($this-data) = 0) return;
 
 
Count the elements in $this-data = @file_get_contents( $file );
If more then one then loop else use the code below:

ex:
if( count( $this-data = @file_get_contents( $file )  1 ) ) {
 foreach( $this-data as $key = $value ) {
  // show your titles etc.
 }
} else {
 
 // get the location
 
 $attr = explode('', $this-tag('item'));
 
 
 $return['title'] = $attr[1];
 
 $return['title'] = substr($return['title'],
 6);
 
  
 
 $return['description'] = $attr[7];
 
 $return['description'] =
 substr($return['description'], 2);
 
  
 
 return $return;
 
 }
 
 
 
 function view_news()
 
 {
 
 
 
 $currentNews = newsfeed::getNews();
 
 
 
 $NEWS=
 'strong'.$currentNews['title'].'/strongbr'.$currentNews['description']
 ..'br/';
 
 
 
 return $NEWS;
 
 
 
 }
 
  
 
 function tag($tag, $skip=0) 
 
 {
 
 $start = -1;
 
 for($i = 0; $i = $skip; $i++)
 
 $start = strpos($this-data,
 {$tag}, $start + 1);
 
 if($start === false) return false;
 
 $start += strlen($tag) + 1;
 
 $end = strpos($this-data, /{$tag},
 $start);
 
 if($end === false)
 
 $end = strpos($this-data,
 '/', $start);
 
 return trim(substr($this-data, $start, $end
 - $start));
 
 }
 
 


- --
Jason Gerfen

I practice my religion
 while stepping on your
 toes...
~The Ditty Bops
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.7 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFHTGMM5vk8bwKVAaIRAhAjAJ9FklveFH1PORVl0HC9nCb+klgcUACeOren
RgXSIP0bl/bt9rI6g9a/6Uk=
=y9XX
-END PGP SIGNATURE-

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



RE: [PHP-DB] array issue

2003-08-17 Thread Aaron Wolski
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:[EMAIL PROTECTED]
 Sent: August 17, 2003 11:31 AM
 To: PHP-DB
 Subject: [PHP-DB] 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



RE: [PHP-DB] array issue

2003-08-17 Thread jeffrey_n_Dyke

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   

  [EMAIL PROTECTED]To:   'OpenSource' [EMAIL 
PROTECTED], 'PHP-DB' [EMAIL PROTECTED]  
  z.com   cc: 

   Subject:  RE: [PHP-DB] 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:[EMAIL PROTECTED]
 Sent: August 17, 2003 11:31 AM
 To: PHP-DB
 Subject: [PHP-DB] 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



RE: [PHP-DB] array issue

2003-08-17 Thread Aaron Wolski
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: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
 Sent: August 17, 2003 11:48 AM
 To: Aaron Wolski
 Cc: 'PHP-DB'; 'OpenSource'
 Subject: RE: [PHP-DB] 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
   [EMAIL PROTECTED]To:
'OpenSource'
 [EMAIL PROTECTED], 'PHP-DB' [EMAIL PROTECTED]
   z.com   cc:
Subject:  RE: [PHP-DB]
 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:[EMAIL PROTECTED]
  Sent: August 17, 2003 11:31 AM
  To: PHP-DB
  Subject: [PHP-DB] 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



Re: [PHP-DB] array issue

2003-08-17 Thread OpenSource
Hey guys thanks a lot
your method worked perfect Aaron, thanks
and that serialize() function, hummm i got to go do some reading and
testing.

thanks for enlightenment and the assistance guys.

RedHat.OpenSource.bz

- Original Message - 
From: Aaron Wolski [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Cc: 'PHP-DB' [EMAIL PROTECTED]; 'OpenSource' [EMAIL PROTECTED]
Sent: Sunday, August 17, 2003 10:04 AM
Subject: RE: [PHP-DB] array issue


 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: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
  Sent: August 17, 2003 11:48 AM
  To: Aaron Wolski
  Cc: 'PHP-DB'; 'OpenSource'
  Subject: RE: [PHP-DB] 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
[EMAIL PROTECTED]To:
 'OpenSource'
  [EMAIL PROTECTED], 'PHP-DB' [EMAIL PROTECTED]
z.com   cc:
 Subject:  RE: [PHP-DB]
  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:[EMAIL PROTECTED]
   Sent: August 17, 2003 11:31 AM
   To: PHP-DB
   Subject: [PHP-DB] 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


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



RE: [PHP-DB] array issue

2003-08-17 Thread Aaron Wolski
Hey,

That's what we're here for :)

As for serialize? It's a great function if you need to preserve an array
in its original form.

Useful for sending back and forth between pages in the URL. Though, I'd
never use on an open URL for the general public. Maybe in an
Administration system not seen by many users.

Aaron

 -Original Message-
 From: OpenSource [mailto:[EMAIL PROTECTED]
 Sent: August 17, 2003 12:28 PM
 To: Aaron Wolski
 Cc: PHP-DB; [EMAIL PROTECTED]
 Subject: Re: [PHP-DB] array issue
 Importance: High
 
 Hey guys thanks a lot
 your method worked perfect Aaron, thanks
 and that serialize() function, hummm i got to go do some reading and
 testing.
 
 thanks for enlightenment and the assistance guys.
 
 RedHat.OpenSource.bz
 
 - Original Message -
 From: Aaron Wolski [EMAIL PROTECTED]
 To: [EMAIL PROTECTED]
 Cc: 'PHP-DB' [EMAIL PROTECTED]; 'OpenSource'
 [EMAIL PROTECTED]
 Sent: Sunday, August 17, 2003 10:04 AM
 Subject: RE: [PHP-DB] array issue
 
 
  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: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
   Sent: August 17, 2003 11:48 AM
   To: Aaron Wolski
   Cc: 'PHP-DB'; 'OpenSource'
   Subject: RE: [PHP-DB] 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
 [EMAIL PROTECTED]To:
  'OpenSource'
   [EMAIL PROTECTED], 'PHP-DB' [EMAIL PROTECTED]
 z.com   cc:
  Subject:  RE:
[PHP-DB]
   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:[EMAIL PROTECTED]
Sent: August 17, 2003 11:31 AM
To: PHP-DB
Subject: [PHP-DB] 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




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



Re: [PHP-DB] Array Issue help please

2003-01-20 Thread Jason Wong
On Monday 20 January 2003 17:50, Dave Carrera wrote:

 I have nearly got this working but it dose not seem to loop though or
 return the result

 I have done something wrong and I ask one of you coders that are much
 cleverer that I to glance over my code to see the obvious mistake / s.

Can you describe in more detail how your code doesn't behave the way you 
expected it to behave? 

So do you see anything at all?

What exactly does it do?

Error messages?

Have you checked the logs?

Have you tried echo() on the important variables to see what they contain?

-- 
Jason Wong - Gremlins Associates - www.gremlins.biz
Open Source Software Systems Integrators
* Web Design  Hosting * Internet  Intranet Applications Development *


/*
The last time I saw him he was walking down Lover's Lane holding his own hand.
-- Fred Allen
*/


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