[PHP] Code errors

2002-07-18 Thread Chris Crane

I am trying some code and it works except I get the following errors...
Warning: Undefined offset: 5 in
c:\www\htdocs\demos\havasuinternet\havasuinternet-lib.php on line 247
Warning: Undefined offset: 4 in
c:\www\htdocs\demos\havasuinternet\havasuinternet-lib.php on line 247
Warning: Undefined offset: 3 in
c:\www\htdocs\demos\havasuinternet\havasuinternet-lib.php on line 247
Warning: Undefined offset: 2 in
c:\www\htdocs\demos\havasuinternet\havasuinternet-lib.php on line 247
Warning: Undefined offset: 1 in
c:\www\htdocs\demos\havasuinternet\havasuinternet-lib.php on line 247


Here is the code, could someone tell me what's wrong. I don't see anything
wrong...

function HistoricalStock($sym) {
 $LookupURL =
http://table.finance.yahoo.com/table.csv?a=7b=1c=2002d=7e=17f=2002s=$
symy=0g=dignore=.csv;
 $Results = implode('', file($LookupURL));
 $Data = explode(\n, $Results);
 print 'table width=100% border=0 cellspacing=1 cellpadding=0
bgcolor=#6699cctr bgcolor=#FF';
 foreach($Data as $Line) {
  list($H_Date, $H_Open, $H_High, $H_Low, $H_Close, $H_Volume) = split(,,
$Line);
  print tr bgcolor=\#FF\

td$H_Date/td\ntd$H_Open/td\ntd$H_High/td\ntd$H_Low/td\ntd$
H_Close/td\ntd$H_Volume/td\n/tr;
  }
 print '/table';
}



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




Re: [PHP] Code errors

2002-07-18 Thread Chris Crane

Hey thank Dan, I will try this.
Does List waste lots of time and memory?

Normally, I create a function and global a bunch of variables to be used
later on the HTML/PHP file. After I global the variables I split the string
using the List function. I do that for stock quotes from YAHOO so I can code
the layout in like Dreamweaver and place the varaibles where I would like
instead of the function writing out the html for me. Is that bad?



Analysis  Solutions [EMAIL PROTECTED] wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
 On Thu, Jul 18, 2002 at 10:14:25AM -0400, Chris Crane wrote:

  Warning: Undefined offset: 5 in

 Means your array doesn't have that key in it.  I bet you're running into
 blank lines in your file.


  $Results = implode('', file($LookupURL));
  $Data = explode(\n, $Results);

 Uh, you do realize that you're flip flopping the data around here for no
 reason.  file() already creates an array.  But you go through the
 unnecessary steps of compressing that array into a string and then
 recreating a new array.  Just do this:

$Data = file($LookupURL);

 That will eliminate your errors by not adding extra blank lines.


   foreach($Data as $Line) {
list($H_Date, $H_Open, $H_High, $H_Low, $H_Close, $H_Volume) =
split(,,
  $Line);
print tr bgcolor=\#FF\
 
td$H_Date/td\ntd$H_Open/td\ntd$H_High/td\ntd$H_Low/td\ntd$
  H_Close/td\ntd$H_Volume/td\n/tr;
}

 But, your whole approach is wasteful.  As I said yesterday, use fopen()
 and then fgetcsv().  Forget the file() and split() calls.

 Then, you're wasting time and memory with the list().  Use the resulting
 array directly.

while ( $Line = fgetcsv($fp, 500) ) {
   echo tr td$Line[0]/td td$Line[1]/td ... etc ...;
}

 Or, since you're pringing everything out, you could just do this:

while ( $Line = fgetcsv($fp, 500) ) {
   echo 'trtd' . implode('/tdtd', $Line) . '/td/tr'
}

 --Dan

 --
PHP classes that make web design easier
 SQL Solution  |   Layout Solution   |  Form Solution
 sqlsolution.info  | layoutsolution.info |  formsolution.info
  T H E   A N A L Y S I S   A N D   S O L U T I O N S   C O M P A N Y
  4015 7 Av #4AJ, Brooklyn NY v: 718-854-0335 f: 718-854-0409



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




Re: [PHP] Code errors

2002-07-18 Thread Chris Crane

ok here is what I came up with:
How's this?
function HistoricalStock($sym) {
 $row = 1;
 $Data =
fopen(http://table.finance.yahoo.com/table.csv?a=7b=1c=2002d=7e=17f=20
02s=$symy=0g=dignore=.csv,r);
 print 'table width=100% border=0 cellspacing=1 cellpadding=0
bgcolor=#6699cctr bgcolor=#FF';

 while ($Line = fgetcsv ($Data, 1000, ,)) {
  if($row == 1) {
   echo tr bgcolor=\#FF\ tdb$Line[0]/b/td
tdb$Line[1]/b/td tdb$Line[2]/b/td
 tdb$Line[3]/b/td tdb$Line[4]/b/td
tdb$Line[5]/b/td/tr;
   }
  else {
   echo tr bgcolor=\#FF\ td$Line[0]/td tdLine[1]/td
td$Line[2]/td
   td$Line[3]/td td$Line[4]/td td$Line[5]/td/tr;
}
  $row++;
  }

 print '/table';
 fclose($Data);
}

Analysis  Solutions [EMAIL PROTECTED] wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
 On Thu, Jul 18, 2002 at 10:14:25AM -0400, Chris Crane wrote:

  Warning: Undefined offset: 5 in

 Means your array doesn't have that key in it.  I bet you're running into
 blank lines in your file.


  $Results = implode('', file($LookupURL));
  $Data = explode(\n, $Results);

 Uh, you do realize that you're flip flopping the data around here for no
 reason.  file() already creates an array.  But you go through the
 unnecessary steps of compressing that array into a string and then
 recreating a new array.  Just do this:

$Data = file($LookupURL);

 That will eliminate your errors by not adding extra blank lines.


   foreach($Data as $Line) {
list($H_Date, $H_Open, $H_High, $H_Low, $H_Close, $H_Volume) =
split(,,
  $Line);
print tr bgcolor=\#FF\
 
td$H_Date/td\ntd$H_Open/td\ntd$H_High/td\ntd$H_Low/td\ntd$
  H_Close/td\ntd$H_Volume/td\n/tr;
}

 But, your whole approach is wasteful.  As I said yesterday, use fopen()
 and then fgetcsv().  Forget the file() and split() calls.

 Then, you're wasting time and memory with the list().  Use the resulting
 array directly.

while ( $Line = fgetcsv($fp, 500) ) {
   echo tr td$Line[0]/td td$Line[1]/td ... etc ...;
}

 Or, since you're pringing everything out, you could just do this:

while ( $Line = fgetcsv($fp, 500) ) {
   echo 'trtd' . implode('/tdtd', $Line) . '/td/tr'
}

 --Dan

 --
PHP classes that make web design easier
 SQL Solution  |   Layout Solution   |  Form Solution
 sqlsolution.info  | layoutsolution.info |  formsolution.info
  T H E   A N A L Y S I S   A N D   S O L U T I O N S   C O M P A N Y
  4015 7 Av #4AJ, Brooklyn NY v: 718-854-0335 f: 718-854-0409



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




Re: [PHP] Code errors

2002-07-18 Thread Analysis Solutions

On Thu, Jul 18, 2002 at 11:35:55AM -0400, Chris Crane wrote:
 Hey thank Dan, I will try this.
 Does List waste lots of time and memory?

It does if you don't need to do it.

Just put the data you really need into memory.  Forget about the rest.

If you already have something in memory, don't duplicate it.


 Normally, I create a function and global a bunch of variables to be used
 later on the HTML/PHP file.

If you're globaling the variables, why not just write the code without
enclosing it in a function?


 After I global the variables I split the string
 using the List function. I do that for stock quotes from YAHOO so I can code
 the layout in like Dreamweaver and place the varaibles where I would like
 instead of the function writing out the html for me. Is that bad?

In general, it makes sense, but, does it make the most sense.  Depends on 
the situation.

But, in this situation, you're printing out a whole table of the data, so
your way doesn't make sense.

A: No.
Q: Is okay to top post and/or quote the entirety of the a post?

--Dan

-- 
   PHP classes that make web design easier
SQL Solution  |   Layout Solution   |  Form Solution
sqlsolution.info  | layoutsolution.info |  formsolution.info
 T H E   A N A L Y S I S   A N D   S O L U T I O N S   C O M P A N Y
 4015 7 Av #4AJ, Brooklyn NY v: 718-854-0335 f: 718-854-0409

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