2 <?php sections in one doc?

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

    2 <?php sections in one doc?

    Hi all,

    This is a newbie question but I have been struggling with this for ages. I
    have a document with 2 separate <?php sections of code. I would like to
    declare some variables in the first section and then read these in the
    second but do not seem to be able to do this. Can someone please let me in
    on how! :)

    Thanks in advance for the help.

    Best Regards,
    David


  • Pedro

    #2
    Re: 2 &lt;?php sections in one doc?

    David Hickman wrote:[color=blue]
    >This is a newbie question but I have been struggling with this for ages. I
    >have a document with 2 separate <?php sections of code. I would like to
    >declare some variables in the first section and then read these in the
    >second but do not seem to be able to do this. Can someone please let me in
    >on how! :)[/color]

    How about some code?

    The following works as expected ...

    <?php
    echo '<hr />';
    $var1 = 'one';
    $var2 = 'two';
    ?>
    <table>
    <tr><th>HTML</th></tr>
    <tr><td>here</td></tr>
    </table>
    <?php
    echo $var1, $var2;
    ?>


    --
    "Yes, I'm positive."
    "Are you sure?"
    "Help, somebody has stolen one of my electrons!"
    Two atoms are talking:

    Comment

    • Joshua Ghiloni

      #3
      Re: 2 &lt;?php sections in one doc?

      David Hickman wrote:
      [color=blue]
      > Hi all,
      >
      > This is a newbie question but I have been struggling with this for ages. I
      > have a document with 2 separate <?php sections of code. I would like to
      > declare some variables in the first section and then read these in the
      > second but do not seem to be able to do this. Can someone please let me in
      > on how! :)
      >
      > Thanks in advance for the help.
      >
      > Best Regards,
      > David
      >
      >[/color]

      Can we see a sample? What you're talking about, if I'm reading this
      correctly, is this:

      <?php $a = 3; ?>
      <html>
      <head></head>
      <body>
      <p>Hello everyone. We all know that 2 + 1 = <?php echo $a ?></p>
      </body>
      </html>

      If that's the case, then it should work like a dream. If it's not what
      you're talking about, please attach some sample code.

      Comment

      • David Hickman

        #4
        Re: 2 &lt;?php sections in one doc?

        thanks guys, that was what I meant. I must have something wrong in my code.
        I'll take a look! :)

        Thanks for the help,
        David


        "Joshua Ghiloni" <jdg11@SPAM.ME. AND.DIE.cwru.ed u> wrote in message
        news:bdq4gm$231 $2@eeyore.INS.c wru.edu...[color=blue]
        > David Hickman wrote:
        >[color=green]
        > > Hi all,
        > >
        > > This is a newbie question but I have been struggling with this for ages.[/color][/color]
        I[color=blue][color=green]
        > > have a document with 2 separate <?php sections of code. I would like to
        > > declare some variables in the first section and then read these in the
        > > second but do not seem to be able to do this. Can someone please let me[/color][/color]
        in[color=blue][color=green]
        > > on how! :)
        > >
        > > Thanks in advance for the help.
        > >
        > > Best Regards,
        > > David
        > >
        > >[/color]
        >
        > Can we see a sample? What you're talking about, if I'm reading this
        > correctly, is this:
        >
        > <?php $a = 3; ?>
        > <html>
        > <head></head>
        > <body>
        > <p>Hello everyone. We all know that 2 + 1 = <?php echo $a ?></p>
        > </body>
        > </html>
        >
        > If that's the case, then it should work like a dream. If it's not what
        > you're talking about, please attach some sample code.
        >[/color]


        Comment

        Working...