echo or not to echo?

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

    echo or not to echo?

    I have a couple pages that have tables, whats best use echo to produce the
    full table with the variables or is it best to just make the table in plain
    html and use <?php echo ('$va'l); ?> when i need to see some value.

    Example i have tables like this
    echo '<div align="',$align ,'"><table border="0" cellpadding="2"
    cellspacing="0" width="',$large ur,'">';
    echo '<tr><td bgcolor="',$tit re_bgcolor,'">< font face="',$titre_ face,'"
    size="',$titre_ size,'" color="',$titre _color,'">&nbsp ;Messages
    </font></td>';
    echo '<td height="24" bgcolor="',$tit re_bgcolor,'">< font
    face="',$titre_ face,'" size="',$titre_ size,'"
    color="',$titre _color,'">&nbsp ;Author :</font></td>';
    echo '<td bgcolor="',$tit re_bgcolor,'">< font face="',$titre_ face,'"
    size="',$titre_ size,'" color="',$titre _color,'">Posts :</font></td>';
    echo '<td bgcolor="',$tit re_bgcolor,'" width="140"><fo nt
    face="',$titre_ face,'" size="',$titre_ size,'" color="',$titre _color,'">Last
    post :</font></td></tr>';

    but sometimes i just leave the php like this ?> my table here and i use
    <?php echo ('$val'); ?> when i need it.

    Both seem to be prety much the same thing to me, i just dont want to waste
    processing power with such things even if in both cases it doesnt take that
    much time to load the page.


  • Pedro Graca

    #2
    Re: echo or not to echo?

    Marco wrote:[color=blue]
    > I have a couple pages that have tables, whats best use echo to produce the
    > full table with the variables or is it best to just make the table in plain
    > html and use <?php echo ('$va'l); ?> when i need to see some value.[/color]

    Parse Error?
    <?php echo ('$va'l); ?>

    or do you mean
    <?php echo ('$val'); ?>
    to print 4 characters: $, v, a, l

    or do you mean
    <?php echo ($val); ?>
    to print /whatever/ the variable $val contains? :)
    [color=blue]
    > Example i have tables like this
    > echo '<div align="',$align ,'"><table border="0" cellpadding="2"
    > cellspacing="0" width="',$large ur,'">';[/color]

    I do a lot of this ...

    [color=blue]
    > but sometimes i just leave the php like this ?> my table here and i use
    ><?php echo ('$val'); ?> when i need it.[/color]

    almost never of this ...

    [color=blue]
    > Both seem to be prety much the same thing to me, i just dont want to waste
    > processing power with such things even if in both cases it doesnt take that
    > much time to load the page.[/color]

    and I also do a lot of

    echo <<<HTML
    <div align="$align"> <table border="0" cellpadding="2" cellspacing="0"
    width="$largeur ">
    HTML;

    I would worry more about the code structure and readability than
    processing power.

    When it doesn't matter, eg:

    echo 'your name is ' . $name; // or
    echo 'your name is ', $name; // or
    echo "your name is $name";

    I will test them (a few thousand times) and use the fastest -- as it
    happens, the fastest is also the version I like better :)
    --
    --= my mail box only accepts =--
    --= Content-Type: text/plain =--
    --= Size below 10001 bytes =--

    Comment

    • Stephen Poley

      #3
      Re: echo or not to echo?

      On Thu, 26 Feb 2004 23:50:00 +0100, "Marco" <mpgtlatbluewin dotch> wrote:
      [color=blue]
      >I have a couple pages that have tables, whats best use echo to produce the
      >full table with the variables or is it best to just make the table in plain
      >html and use <?php echo ('$va'l); ?> when i need to see some value.
      >
      >Example i have tables like this
      >echo '<div align="',$align ,'"><table border="0" cellpadding="2"
      >cellspacing="0 " width="',$large ur,'">';
      >echo '<tr><td bgcolor="',$tit re_bgcolor,'">< font face="',$titre_ face,'"
      >size="',$titre _size,'" color="',$titre _color,'">&nbsp ;Messages
      ></font></td>';
      >echo '<td height="24" bgcolor="',$tit re_bgcolor,'">< font
      >face="',$titre _face,'" size="',$titre_ size,'"
      >color="',$titr e_color,'">&nbs p;Author :</font></td>';
      >echo '<td bgcolor="',$tit re_bgcolor,'">< font face="',$titre_ face,'"
      >size="',$titre _size,'" color="',$titre _color,'">Posts :</font></td>';
      >echo '<td bgcolor="',$tit re_bgcolor,'" width="140"><fo nt
      >face="',$titre _face,'" size="',$titre_ size,'" color="',$titre _color,'">Last
      >post :</font></td></tr>';[/color]

      Not quite what you were asking, but you'd improve it enormously by doing
      something like:

      <table class=messages>
      <tr><th>Message s</th><th>Author</th><th>Posts</th><th>Last
      post</th></tr>

      And have a separate CSS file, something like:

      ..messages th { font-family: Helvetia, Arial; color: black;
      background-color: red; padding: 0.5em; }

      Much easier to understand, much easier to maintain, more accessible
      (because readers with special requirements can substitute their own
      stylesheet) and faster to download.

      And drop the width attributes on the table altogether; the reader's
      browser most probably knows better how to arrange the stuff in his
      window than you do.

      HTH

      --
      Stephen Poley

      Comment

      • Marco

        #4
        Re: echo or not to echo?

        Indeed CSS opens a few more doors, i heard about it here and there but never
        realy tryed to know what it realy was.
        All my site needs to have 3 differents layouts basicly only the colors will
        change from one page to another and with CSS its alot easier and faster to
        inplement.
        Thanks for your advice, i'll google a "little" to know more about CSS has i
        know prety much nothing about it.


        "Stephen Poley" <sbpoleySpicedH amTrap@xs4all.n l> wrote in message
        news:hcav30l8g4 rdq2gtgmma034c8 ehh0qin34@4ax.c om...[color=blue]
        > On Thu, 26 Feb 2004 23:50:00 +0100, "Marco" <mpgtlatbluewin dotch> wrote:
        >[color=green]
        > >I have a couple pages that have tables, whats best use echo to produce[/color][/color]
        the[color=blue][color=green]
        > >full table with the variables or is it best to just make the table in[/color][/color]
        plain[color=blue][color=green]
        > >html and use <?php echo ('$va'l); ?> when i need to see some value.
        > >
        > >Example i have tables like this
        > >echo '<div align="',$align ,'"><table border="0" cellpadding="2"
        > >cellspacing="0 " width="',$large ur,'">';
        > >echo '<tr><td bgcolor="',$tit re_bgcolor,'">< font face="',$titre_ face,'"
        > >size="',$titre _size,'" color="',$titre _color,'">&nbsp ;Messages
        > ></font></td>';
        > >echo '<td height="24" bgcolor="',$tit re_bgcolor,'">< font
        > >face="',$titre _face,'" size="',$titre_ size,'"
        > >color="',$titr e_color,'">&nbs p;Author :</font></td>';
        > >echo '<td bgcolor="',$tit re_bgcolor,'">< font face="',$titre_ face,'"
        > >size="',$titre _size,'" color="',$titre _color,'">Posts :</font></td>';
        > >echo '<td bgcolor="',$tit re_bgcolor,'" width="140"><fo nt
        > >face="',$titre _face,'" size="',$titre_ size,'"[/color][/color]
        color="',$titre _color,'">Last[color=blue][color=green]
        > >post :</font></td></tr>';[/color]
        >
        > Not quite what you were asking, but you'd improve it enormously by doing
        > something like:
        >
        > <table class=messages>
        > <tr><th>Message s</th><th>Author</th><th>Posts</th><th>Last
        > post</th></tr>
        >
        > And have a separate CSS file, something like:
        >
        > .messages th { font-family: Helvetia, Arial; color: black;
        > background-color: red; padding: 0.5em; }
        >
        > Much easier to understand, much easier to maintain, more accessible
        > (because readers with special requirements can substitute their own
        > stylesheet) and faster to download.
        >
        > And drop the width attributes on the table altogether; the reader's
        > browser most probably knows better how to arrange the stuff in his
        > window than you do.
        >
        > HTH
        >
        > --
        > Stephen Poley[/color]


        Comment

        • Marco

          #5
          Re: echo or not to echo?

          I meant <?php echo ($val); ?>, it was easier to me to understand at the
          start cause i could draw the tables with front page ;) and then just use
          <?php echo ($val); ?> when i need some variable.

          Didnt know about this possibility[color=blue]
          > echo <<<HTML
          > <div align="$align"> <table border="0" cellpadding="2" cellspacing="0"
          > width="$largeur ">
          > HTML;[/color]

          Thanks for sharing your point of view ;)

          "Pedro Graca" <hexkid@hotpop. com> wrote in message
          news:c1m48l$1jq u7u$1@ID-203069.news.uni-berlin.de...[color=blue]
          > Marco wrote:[color=green]
          > > I have a couple pages that have tables, whats best use echo to produce[/color][/color]
          the[color=blue][color=green]
          > > full table with the variables or is it best to just make the table in[/color][/color]
          plain[color=blue][color=green]
          > > html and use <?php echo ('$va'l); ?> when i need to see some value.[/color]
          >
          > Parse Error?
          > <?php echo ('$va'l); ?>
          >
          > or do you mean
          > <?php echo ('$val'); ?>
          > to print 4 characters: $, v, a, l
          >
          > or do you mean
          > <?php echo ($val); ?>
          > to print /whatever/ the variable $val contains? :)
          >[color=green]
          > > Example i have tables like this
          > > echo '<div align="',$align ,'"><table border="0" cellpadding="2"
          > > cellspacing="0" width="',$large ur,'">';[/color]
          >
          > I do a lot of this ...
          >
          >[color=green]
          > > but sometimes i just leave the php like this ?> my table here and i use
          > ><?php echo ('$val'); ?> when i need it.[/color]
          >
          > almost never of this ...
          >
          >[color=green]
          > > Both seem to be prety much the same thing to me, i just dont want to[/color][/color]
          waste[color=blue][color=green]
          > > processing power with such things even if in both cases it doesnt take[/color][/color]
          that[color=blue][color=green]
          > > much time to load the page.[/color]
          >
          > and I also do a lot of
          >
          > echo <<<HTML
          > <div align="$align"> <table border="0" cellpadding="2" cellspacing="0"
          > width="$largeur ">
          > HTML;
          >
          > I would worry more about the code structure and readability than
          > processing power.
          >
          > When it doesn't matter, eg:
          >
          > echo 'your name is ' . $name; // or
          > echo 'your name is ', $name; // or
          > echo "your name is $name";
          >
          > I will test them (a few thousand times) and use the fastest -- as it
          > happens, the fastest is also the version I like better :)
          > --
          > --= my mail box only accepts =--
          > --= Content-Type: text/plain =--
          > --= Size below 10001 bytes =--[/color]


          Comment

          • Pedro Graca

            #6
            Re: echo or not to echo?

            Marco top-posted (corrected):[color=blue][color=green]
            >> echo <<<HTML
            >> <div align="$align"> <table border="0" cellpadding="2" cellspacing="0"
            >> width="$largeur ">
            >> HTML;[/color][/color]
            [color=blue]
            > Didnt know about this possibility[/color]

            It's called heredoc syntax. Read all about it

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

            Comment

            • R. Rajesh Jeba Anbiah

              #7
              Re: echo or not to echo?

              "Marco" <mpgtlatbluewin dotch> wrote in message news:<403e7816_ 3@news.bluewin. ch>...[color=blue]
              > I have a couple pages that have tables, whats best use echo to produce the
              > full table with the variables or is it best to just make the table in plain
              > html and use <?php echo ('$va'l); ?> when i need to see some value.
              >
              > Example i have tables like this
              > echo '<div align="',$align ,'"><table border="0" cellpadding="2"
              > cellspacing="0" width="',$large ur,'">';
              > echo '<tr><td bgcolor="',$tit re_bgcolor,'">< font face="',$titre_ face,'"
              > size="',$titre_ size,'" color="',$titre _color,'">&nbsp ;Messages
              > </font></td>';
              > echo '<td height="24" bgcolor="',$tit re_bgcolor,'">< font
              > face="',$titre_ face,'" size="',$titre_ size,'"
              > color="',$titre _color,'">&nbsp ;Author :</font></td>';
              > echo '<td bgcolor="',$tit re_bgcolor,'">< font face="',$titre_ face,'"
              > size="',$titre_ size,'" color="',$titre _color,'">Posts :</font></td>';
              > echo '<td bgcolor="',$tit re_bgcolor,'" width="140"><fo nt
              > face="',$titre_ face,'" size="',$titre_ size,'" color="',$titre _color,'">Last
              > post :</font></td></tr>';
              >
              > but sometimes i just leave the php like this ?> my table here and i use
              > <?php echo ('$val'); ?> when i need it.
              >
              > Both seem to be prety much the same thing to me, i just dont want to waste
              > processing power with such things even if in both cases it doesnt take that
              > much time to load the page.[/color]


              I used to avoid echo and completely prefer short-tags like:

              <table>
              <tr>
              <td><?=$foo11?> </td><td><?=$foo1 2?></td><td><?=$foo1 3?></td>
              </tr>
              <tr>
              <td><?=$foo21?> </td><td><?=$foo2 2?></td><td><?=$foo2 3?></td>
              </tr>
              <tr>
              <td><?=$foo31?> </td><td><?=$foo3 2?></td><td><?=$foo3 3?></td>
              </tr>
              </table>

              As you see, it is DW friendly. You can easily add "colours" by
              opening it in DW. Can add styles, etc too quickly. If you use echo, DW
              will show entire code as a PHP and that is hard to touch to add
              "colours".

              --
              "Success is not what you achieve, but it is what you die for"
              If you live in USA, please support John Edwards.
              Email: rrjanbiah-at-Y!com

              Comment

              Working...