Forum Moderators: coopster

Message Too Old, No Replies

partial display of var's

fgetcsv

         

HoMeR

1:27 pm on Dec 2, 2003 (gmt 0)

10+ Year Member



Hi , i'me having troubles reading my data from a txt file?
and cant find my problem, plz help

---->
while ($data = fgetcsv ($handle, 700 , "¦")) {
$num = count ($data);
$catnaam[$row]=$data[0] ; $catkeyword[$row]=$data[1] ;

if ( $weergave == 1 ) {
echo $row . "&nbsp;-&nbsp;" . $catnaam[$row] . "&nbsp;<b>keywords:</b>&nbsp;" . $catkeyword[$row] . "<br>" ;
}
elseif ( $weergave == 2 ) {
echo $row . "&nbsp;-&nbsp;" . $catnaam[$row] . "<br>\n" ;
}
else { if ( $weergave == 0 ) { echo $catnaam[$row] . "<br>\n" ;

}}

$row++;
}
<---

this script shows the $catnaam var , but reads?/shows? only the first character of the $catkeyword?¿?¿

I'me guessing it's a painfully easy typo mistake?
or isn't?

Timotheos

4:37 pm on Dec 2, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi Homer,

I can't see anything wrong. Maybe you could give us a few example lines from the text file.

Tim

HoMeR

7:24 pm on Dec 2, 2003 (gmt 0)

10+ Year Member



sure the text file looks like this

cpu¦amd intel¦
memory¦hp intel mtec¦

in my test-run ime using; $weergave=1 ,
and the exact output is;

1 - cpu keywords: a
2 - memory keywords: h

?

thnx

jatar_k

8:03 pm on Dec 2, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld HoMeR,

Maybe try something like below to see if the data coming from the file is ok

echo "<br>",$data[0],":",$data[1];

or

print_r($data);

put one of those right after the while loop to see if it is reading the proper data.

Things to look at
1. the actual data - the lines you posted look fine
2. the initial read - dumping the data as above will show you what is going into the vars, you may also not be getting enough data from each line and could try using a larger number in your fgetcsv function. It should always be longer than the longest line of data.
3. your assignments ie. are you grabbing the right data
4. your output function - looks ok as well

Timotheos

8:12 pm on Dec 2, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hmmm.... I just cut and pasted your code and put this at the front.

$row = 1;
$weergave = 1;
$handle = fopen ("test.txt","r");

and it worked fine. Curious.

HoMeR

9:31 pm on Dec 2, 2003 (gmt 0)

10+ Year Member



i'me using this code as a include. (srry 4 misinforming)

i've written another page where i would need this list, and it workes fine too.
The difference between the two pages, is that the $catnaam is used, and that i opend, appended too, and closed the .txt file, before the include re-opens it, to display the list as shown above.