473,386 Members | 1,832 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Getting single char from buffered reader

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
5 2297
pbmods
5,821 Expert 4TB
Heya, BOMEz.

What's an example of the HTML that gets output?
Oct 24 '08 #2
BOMEz
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
5,821 Expert 4TB
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
BOMEz
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
5,821 Expert 4TB
Oops. Glad to hear you were able to get it working!

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

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

Similar topics

4
by: sathya | last post by:
I have come across the following code which treys to implement the strcat function. It may be wrong or correct, but it is using integer zero instead of appending the C string terminator '\0'. ...
9
by: kernelxu | last post by:
hi,everybody. I calling function setbuf() to change the characteristic of standsrd input buffer. some fragment of the progrem is: (DEV-C++2.9.9.2) #include <stdio.h> #include <stdlib.h> int...
3
by: TeekUS | last post by:
hey ppl, i am currently developing a parsing application my input is a 10MB english text file the parsing works fine however every now and then a non english character appears that messes...
5
by: Heriberto | last post by:
Hi, I'd like to know how to work with excel using C#. I known how to do it in Delphi but I new in C#. I just want a small exemple. And if anyone knows if there are diferrence working with excel...
4
by: Zephyr . via .NET 247 | last post by:
(Type your message here) -------------------------------- From: Zephyr . hey, i got trouble getting integers out of a plain text file. i dont want to use binary files, just plain text files...
2
by: Michael | last post by:
Hi All, I have something going wrong with the XmlTextReader. I have a function that reads the following XML example. For some reason the code is only getting two of the 3 Values elements. Here is...
5
by: tienlx | last post by:
Hi all, I'm have a problem that i don't know how to convert object to char in C# . Does anybody know ? Thanks.
3
by: Zach | last post by:
Hello, This might be a rather basic question, but I've tried a few things and I can't really find a solution as elegant as what I'd like for this problem. The situation is this - I have a file...
0
by: rich | last post by:
Hi all, I have a fairly complex "feed" application that recieves messages from an external user-supplied API via a callback function, and attempts to forward these messages to another...
15
by: jyohere | last post by:
I am using buffered Reader.....some problem arises ...dnt know why....am using the following code to read a big file about 8MB. path = "/home/t.txt" File file=new File(path); FileReader...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.