Getting single char from buffered reader

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • BOMEz
    New Member
    • Dec 2007
    • 40

    Getting single char from buffered reader

    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("categori es.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='$categor y[$i]'>$description[$i]</option>" ;
    }
    ?> [/PHP]

    any ideas guys?
  • pbmods
    Recognized Expert Expert
    • Apr 2007
    • 5821

    #2
    Heya, BOMEz.

    What's an example of the HTML that gets output?

    Comment

    • BOMEz
      New Member
      • Dec 2007
      • 40

      #3
      [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='$categor y[$i]'>$description[$i]</option>" ;
      }
      ?>
      [/PHP]

      Above is the HTML wrap around the PHP to print output.

      Comment

      • pbmods
        Recognized Expert Expert
        • Apr 2007
        • 5821

        #4
        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.

        Comment

        • BOMEz
          New Member
          • Dec 2007
          • 40

          #5
          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.

          Comment

          • pbmods
            Recognized Expert Expert
            • Apr 2007
            • 5821

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

            Good luck with your project!

            Comment

            Working...