PHP steamed output not generating proper HTML

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Claus Mygind
    Contributor
    • Mar 2008
    • 571

    PHP steamed output not generating proper HTML

    I'm in the process of recoding some apps into PHP.

    At one point I am loading a list box. I test the value being loaded, if it is a match with the value from the table record I add the "selected" to the option.

    This should make that item appear in the drop down list.

    When I examine the output in the browser I can see that the PHP code executed properly and added the "selected" attribute to the proper item in the list. However, the first item and NOT the selected item is displayed.

    Perhaps this is a question for the HTML forum, however in my existing code in the other language which streams out this same page, the list box displays properly, so I'm thinking I have a PHP issue. Any suggestion is appreciated.

    Here are 3 examples of what I have tried none work.
    Code:
    <select name="DATE_MONTH">
    <?php
      for ($n=0; $n<12; n++){
        $m = $n+1;
        if ($m == $this->cMonth)
        {
    ?>
    	<option value="<?php echo $m;?>" SELECTED><?php echo $this->monthName[$n];?></option>
    <?php
        }else{
    ?>
    	<option value="<?php echo $m;?>"><?php echo $this->monthName[$n];?></option>
    <?php
        }
      }
    ?>
    </select>
    
    <select name="DATE_DAY">
    <?php
      for ($n=1; $n<32; $n++){
        if ($n == $this->cDay)
        {
    	echo '<option value="'.$n.'" selected >'.$n.'</option>';
        }else{
    	echo '<option value="'.$n.'">'.$n.'</option>';
        }
      }
    ?>
    </select>
    
    <select name="DATE_YEAR">
    	<option value="<?php echo $this->pYear;?>"><?php echo $this->pYear;?></option>
    	<option value="<?php echo $this->cYear;?>" selected><?php echo $this->cYear;?></option>
    	<option value="<?php echo $this->nYear;?>"><?php echo $this->nYear;?></option>
    </select>
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    What does the HTML look like on the client side?

    Comment

    • Claus Mygind
      Contributor
      • Mar 2008
      • 571

      #3
      Thanks Rabbit for getting me to take a closer look at my code. I had already decided to take a different approach. In reconstructing the code as it was when I submitted it, so I could display the streamed output as you requested, I noticed an error on line 3 of the code above.

      Code:
       <select name="DATE_MONTH">
      <?php
        for ($n=0; $n<12; n++){
      The variable n did not contain the requisite $ on the incrementer like this:
      Code:
       <select name="DATE_MONTH">
      <?php
        for ($n=0; $n<12; [B][U][I]$[/I][/U][/B]n++){
      I'm surprised the compiler did not report the error before I posted this question.
      Last edited by Claus Mygind; Dec 15 '14, 12:33 PM. Reason: clarify

      Comment

      Working...