stumped by this php database behavior

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • jm

    stumped by this php database behavior

    Consider:

    while ($j < $num2) {
    $parent_id=mysq l_result($resul t2,$j,"parent_i d");
    $fam_first_name =mysql_result($ result2,$j,"fam _first_name");
    $fam_age=mysql_ result($result2 ,$j,"fam_age");
    echo "it is $parent_id";
    echo "<tr id=$parent_id>" ;
    echo "<td></td>";
    echo "<td >$fam_first_nam e</td>";
    echo "<td>$fam_a ge</td>";
    echo "</tr>";
    ++$j;
    }

    The line that says "it is $parent_id" will print the variable.
    The next parent id will skip one if it has two of the same values. I
    know this may not make sense, but:

    it is 1
    it is 3
    it is 3
    it is 6


    but the second three from above will never be in the tr id= tag. i
    hope this makes sens. It just doesn't print in the tag if it has two
    rows.
    thanks.


  • Pedro Graca

    #2
    Re: stumped by this php database behavior

    jm wrote:
    (snip)[color=blue]
    > The line that says "it is $parent_id" will print the variable.
    > The next parent id will skip one if it has two of the same values. I
    > know this may not make sense, but:
    >
    > it is 1
    > it is 3
    > it is 3
    > it is 6
    >
    >
    > but the second three from above will never be in the tr id= tag. i
    > hope this makes sens. It just doesn't print in the tag if it has two
    > rows.[/color]

    Maybe you have something extra in $parent_id.

    Do
    <?php
    echo "<pre>it is [$parent_id]</pre>";
    ?>

    to verify that.

    In your browser the string "it is 3" (notice *two* spaces)
    is shown as "it is 3" (notice *one* space)


    Happy bug hunting :-)
    --
    --= my mail box only accepts =--
    --= Content-Type: text/plain =--
    --= Size below 10001 bytes =--

    Comment

    • jm

      #3
      Re: stumped by this php database behavior

      Pedro Graca <hexkid@hotpop. com> wrote in message news:<buitsv$ie neh$1@ID-203069.news.uni-berlin.de>...[color=blue]
      > jm wrote:
      > (snip)[color=green]
      > > The line that says "it is $parent_id" will print the variable.
      > > The next parent id will skip one if it has two of the same values. I
      > > know this may not make sense, but:
      > >
      > > it is 1
      > > it is 3
      > > it is 3
      > > it is 6
      > >
      > >
      > > but the second three from above will never be in the tr id= tag. i
      > > hope this makes sens. It just doesn't print in the tag if it has two
      > > rows.[/color]
      >
      > Maybe you have something extra in $parent_id.
      >
      > Do
      > <?php
      > echo "<pre>it is [$parent_id]</pre>";
      > ?>
      >
      > to verify that.
      >
      > In your browser the string "it is 3" (notice *two* spaces)
      > is shown as "it is 3" (notice *one* space)
      >
      >
      > Happy bug hunting :-)[/color]

      Thanks. Actually, I found that I had to separate the string on three
      different lines:

      so, for example:

      echo "<td id=";
      echo $parent_id;
      echo ">";

      then it would print. Bizarre. I used to run into these quirks with
      ASP (classic) too.

      Comment

      • Juha Suni

        #4
        Re: stumped by this php database behavior

        jm wrote:[color=blue]
        > Thanks. Actually, I found that I had to separate the string on three
        > different lines:
        >
        > so, for example:
        >
        > echo "<td id=";
        > echo $parent_id;
        > echo ">";
        >
        > then it would print. Bizarre. I used to run into these quirks with
        > ASP (classic) too.[/color]

        Cleaner and faster to write would be just to do
        echo "<td id=" . $parent_id . ">";

        Or even for more performance (although not noticeable):
        echo '<td id=' . $parent_id . '>';

        And finally, to avoid html-problems if the $parent_id happens to contain
        spaces (you never can be too sure), do:

        echo '<td id="' . $parent_id . '">';

        HTH

        --
        Suni

        Comment

        • Tim Van Wassenhove

          #5
          Re: stumped by this php database behavior

          On 2004-01-22, Juha Suni <juha.suni@ilmi antajat.fi> wrote:[color=blue]
          > jm wrote:[color=green]
          >> Thanks. Actually, I found that I had to separate the string on three
          >> different lines:
          >>
          >> so, for example:
          >>
          >> echo "<td id=";
          >> echo $parent_id;
          >> echo ">";
          >>
          >> then it would print. Bizarre. I used to run into these quirks with
          >> ASP (classic) too.[/color]
          >
          > Cleaner and faster to write would be just to do
          > echo "<td id=" . $parent_id . ">";
          >
          > Or even for more performance (although not noticeable):
          > echo '<td id=' . $parent_id . '>';
          >
          > And finally, to avoid html-problems if the $parent_id happens to contain
          > spaces (you never can be too sure), do:
          >
          > echo '<td id="' . $parent_id . '">';[/color]

          As what html concerns, values of an attribute must be put between " " or
          ' '. Thus <td id='value'> is valid too.


          Oh and the last option echo "<td id='{$parent_id }'/>";

          --

          Comment

          Working...