Connecting Tech Pros Worldwide Forums | Help | Site Map

Getting single char from buffered reader

Member
 
Join Date: Dec 2007
Posts: 37
#1: Oct 23 '08
I'm loading a series of descriptions and categories from a text file. I then load the descriptions into a drop down list.

It works all fine when I first load the page, but then I submit some information (including the drop down box info) off the page to another PHP file to record the data into a database, and then I call include to get back to my original page. When I do this though my drop down list only shows the first letter from my descriptions.

To read and display the information I use :
[PHP]<?php
$size =0;
$file = fopen("categories.txt", "r");
//Get categories from categories.txt
while(! feof($file))
{
$category[$size] = fgets($file);
$description[$size]=fgets($file);
$size++;
}
fclose($file);
?>[/PHP]

I then display descriptions in the drop down by doing:
[PHP] <?php
//Display categories from /categories.txt
for ($i=0; $i<$size;$i++)
{
echo"<option value='$category[$i]'>$description[$i]</option>" ;
}
?> [/PHP]

any ideas guys?

pbmods's Avatar
Site Moderator
 
Join Date: Apr 2007
Location: Texas
Posts: 5,435
#2: Oct 24 '08

re: Getting single char from buffered reader


Heya, BOMEz.

What's an example of the HTML that gets output?
Member
 
Join Date: Dec 2007
Posts: 37
#3: Oct 24 '08

re: Getting single char from buffered reader


[PHP] <select name="category" tabindex= "7">
<option value="N/A"> Choose issue</option>
<?php
//Display descriptions from /categories.txt
for ($i=0; $i<$size;$i++)
{
echo"<option value='$category[$i]'>$description[$i]</option>" ;
}
?>
[/PHP]

Above is the HTML wrap around the PHP to print output.
pbmods's Avatar
Site Moderator
 
Join Date: Apr 2007
Location: Texas
Posts: 5,435
#4: Oct 25 '08

re: Getting single char from buffered reader


What is an example of the HTML that's actually getting output? I'm not clear on whether it's only outputting a single character, or the first letter of each line, or the first letter of certain lines.
Member
 
Join Date: Dec 2007
Posts: 37
#5: Oct 27 '08

re: Getting single char from buffered reader


Ah sorry about that, but I got it resolved.

It was only outputting the first character of a line, so if I had in my list:
Alice
Bob
Carl

I would only get
A
B
C

Kind of embarrassing to admit, but the problem was that I was using the same variable name in another file which I was making a call to. This messed everything up since I didn't even notice the fact that the file names were the same since someone else had written it.
pbmods's Avatar
Site Moderator
 
Join Date: Apr 2007
Location: Texas
Posts: 5,435
#6: Oct 28 '08

re: Getting single char from buffered reader


Oops. Glad to hear you were able to get it working!

Good luck with your project!
Reply