By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,888 Members | 1,058 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,888 IT Pros & Developers. It's quick & easy.

Getting single char from buffered reader

P: 40
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?
Oct 23 '08 #1
Share this Question
Share on Google+
5 Replies


pbmods
Expert 5K+
P: 5,821
Heya, BOMEz.

What's an example of the HTML that gets output?
Oct 24 '08 #2

P: 40
[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.
Oct 24 '08 #3

pbmods
Expert 5K+
P: 5,821
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.
Oct 25 '08 #4

P: 40
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.
Oct 27 '08 #5

pbmods
Expert 5K+
P: 5,821
Oops. Glad to hear you were able to get it working!

Good luck with your project!
Oct 28 '08 #6

Post your reply

Sign in to post your reply or Sign up for a free account.