By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,740 Members | 790 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,740 IT Pros & Developers. It's quick & easy.

echo or not to echo?

P: n/a
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="',$largeur,'">';
echo '<tr><td bgcolor="',$titre_bgcolor,'"><font face="',$titre_face,'"
size="',$titre_size,'" color="',$titre_color,'">&nbsp;Messages
</font></td>';
echo '<td height="24" bgcolor="',$titre_bgcolor,'"><font
face="',$titre_face,'" size="',$titre_size,'"
color="',$titre_color,'">&nbsp;Author :</font></td>';
echo '<td bgcolor="',$titre_bgcolor,'"><font face="',$titre_face,'"
size="',$titre_size,'" color="',$titre_color,'">Posts :</font></td>';
echo '<td bgcolor="',$titre_bgcolor,'" width="140"><font
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.
Jul 17 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
Marco wrote:
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.
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? :)
Example i have tables like this
echo '<div align="',$align,'"><table border="0" cellpadding="2"
cellspacing="0" width="',$largeur,'">';
I do a lot of this ...

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

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.


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 =--
Jul 17 '05 #2

P: n/a
On Thu, 26 Feb 2004 23:50:00 +0100, "Marco" <mpgtlatbluewindotch> wrote:
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="',$largeur,'">';
echo '<tr><td bgcolor="',$titre_bgcolor,'"><font face="',$titre_face,'"
size="',$titre_size,'" color="',$titre_color,'">&nbsp;Messages
</font></td>';
echo '<td height="24" bgcolor="',$titre_bgcolor,'"><font
face="',$titre_face,'" size="',$titre_size,'"
color="',$titre_color,'">&nbsp;Author :</font></td>';
echo '<td bgcolor="',$titre_bgcolor,'"><font face="',$titre_face,'"
size="',$titre_size,'" color="',$titre_color,'">Posts :</font></td>';
echo '<td bgcolor="',$titre_bgcolor,'" width="140"><font
face="',$titre_face,'" size="',$titre_size,'" color="',$titre_color,'">Last
post :</font></td></tr>';


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

<table class=messages>
<tr><th>Messages</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
Jul 17 '05 #3

P: n/a
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" <sb******************@xs4all.nl> wrote in message
news:hc********************************@4ax.com...
On Thu, 26 Feb 2004 23:50:00 +0100, "Marco" <mpgtlatbluewindotch> wrote:
I have a couple pages that have tables, whats best use echo to produce thefull table with the variables or is it best to just make the table in plainhtml 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="',$largeur,'">';
echo '<tr><td bgcolor="',$titre_bgcolor,'"><font face="',$titre_face,'"
size="',$titre_size,'" color="',$titre_color,'">&nbsp;Messages
</font></td>';
echo '<td height="24" bgcolor="',$titre_bgcolor,'"><font
face="',$titre_face,'" size="',$titre_size,'"
color="',$titre_color,'">&nbsp;Author :</font></td>';
echo '<td bgcolor="',$titre_bgcolor,'"><font face="',$titre_face,'"
size="',$titre_size,'" color="',$titre_color,'">Posts :</font></td>';
echo '<td bgcolor="',$titre_bgcolor,'" width="140"><font
face="',$titre_face,'" size="',$titre_size,'" color="',$titre_color,'">Lastpost :</font></td></tr>';


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

<table class=messages>
<tr><th>Messages</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

Jul 17 '05 #4

P: n/a
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
echo <<<HTML
<div align="$align"><table border="0" cellpadding="2" cellspacing="0"
width="$largeur">
HTML;
Thanks for sharing your point of view ;)

"Pedro Graca" <he****@hotpop.com> wrote in message
news:c1*************@ID-203069.news.uni-berlin.de... Marco wrote:
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.


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? :)
Example i have tables like this
echo '<div align="',$align,'"><table border="0" cellpadding="2"
cellspacing="0" width="',$largeur,'">';


I do a lot of this ...

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


almost never of this ...

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.


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 =--

Jul 17 '05 #5

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


It's called heredoc syntax. Read all about it
http://www.php.net/manual/en/language.types.string.php
--
--= my mail box only accepts =--
--= Content-Type: text/plain =--
--= Size below 10001 bytes =--
Jul 17 '05 #6

P: n/a
"Marco" <mpgtlatbluewindotch> wrote in message news:<40********@news.bluewin.ch>...
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="',$largeur,'">';
echo '<tr><td bgcolor="',$titre_bgcolor,'"><font face="',$titre_face,'"
size="',$titre_size,'" color="',$titre_color,'">&nbsp;Messages
</font></td>';
echo '<td height="24" bgcolor="',$titre_bgcolor,'"><font
face="',$titre_face,'" size="',$titre_size,'"
color="',$titre_color,'">&nbsp;Author :</font></td>';
echo '<td bgcolor="',$titre_bgcolor,'"><font face="',$titre_face,'"
size="',$titre_size,'" color="',$titre_color,'">Posts :</font></td>';
echo '<td bgcolor="',$titre_bgcolor,'" width="140"><font
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.

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

<table>
<tr>
<td><?=$foo11?></td><td><?=$foo12?></td><td><?=$foo13?></td>
</tr>
<tr>
<td><?=$foo21?></td><td><?=$foo22?></td><td><?=$foo23?></td>
</tr>
<tr>
<td><?=$foo31?></td><td><?=$foo32?></td><td><?=$foo33?></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
Jul 17 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.