Counting variables...

A

Anonymous

Guest
I have this loop which goes through a text list of words and puts them in a URL and array:

Code:
<?php
foreach($word as $wd){
     $fp = fopen("http://www.anywhere.com/{$wd}","r");
     $data = fgetcsv ($fp, 1000, ",");
     fclose ($fp);
}
?>

What I need to do is assign $data a number (important that it be a number and not text etc) after each foreach loop, so that after each loop there is something like $data0001, then $data0002, etc.

Ultimately, each dynamically created variable will then store the CSV values such as $data0001[0], $data0001[1], and so on.

PLEASE HELP!!
 
why cant you use an array instead of the $data001 use $data[1] and so on:

in a loop add this:

$i++;
$data[$i]= "some data";
 
Thanks for your help! I think I am almost there, but not quite. Here's what I have, can you tell me what I am doing wrong? I get no output from the table when I try to test it.

Code:
<?php
foreach($word as $wd){
$fp= fopen("http://www.a.com/info.csv?s={$symbol}&f=sl1d1=.csv","r");
$i++;
$data{$i} = fgetcsv ($fp, 1000000, ",");
fclose ($fp);
}
?>

<table>
<tr><td>Data 0 =</td><td><?php echo "$data0[1]" ?></td></tr>
<tr><td>Data 1 =</td><td><?php echo "$data0[2]" ?></td></tr>
<tr><td>Data 2 =</td><td><?php echo "$data0[3]" ?></td></tr>
<tr><td>Data 3 =</td><td><?php echo "$data1[1]" ?></td></tr>
<tr><td>Data 4 =</td><td><?php echo "$data1[2]" ?></td></tr>
<tr><td>Data 5 =</td><td><?php echo "$data1[3]" ?></td></tr>
<tr><td>Data 6 =</td><td><?php echo "$data2[1]" ?></td></tr>
<tr><td>Data 7 =</td><td><?php echo "$data2[2]" ?></td></tr>
<tr><td>Data 8 =</td><td><?php echo "$data2[3]" ?></td></tr>
</table>


Thank you very much!!
 
The URL calls up 3 different points of data, which I need to be stored in that portion of the array. Let's say that I have two different values for {$symbol}, something like ABC and EFG. When I put those into the URL, I get three unique values for each. I was hoping it would be possible to then have an array setup where the information would be stored like this:

For ABC, assigned as 0001:
$data1[0] (this would be 1st data for ABC)
$data1[1] (this would be 2nd data for ABC)
$data1[2] (this would be 3rd data for ABC)

For EFG, assigned as 0002:
$data2[0] (this would be 1st data for EFG)
$data2[1] (this would be 2nd data for EFG)
$data2[2] (this would be 3rd data for EFG)


I have everything working right when I try to do it without the number part (just using text), but I just need a way to insert some sort of counter. Thank you very much for your help and patience! I have only been learning PHP for about a week.
 
Back
Top