This is a discussion on Whats more efficient? ( echo " "; or <?php echo ?> ) within the PHP General forums, part of the PHP Programming Forums category; Hi everyone, Just a simple doubt and basically your opinion needed. I have an option box on a webpage and ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
Hi everyone,
Just a simple doubt and basically your opinion needed. I have an option box on a webpage and have around 10 options on it and have run into a doubt, which is more efficient to do: 1. <option value="1"<?php if($th_order==1){echo " SELECTED"; } ?>>Something1</option> <option value="2"<?php if($th_order==2){echo " SELECTED"; } ?>>Something2</option> (or) 2. instead of having the <?php and ?> mixed in the HTML is it better to echo/print the whole lines? Thanks, -Ryan |
|
|||
|
Ryan A wrote:
> I have an option box on a webpage and have around 10 options on it and have > run into a doubt, > which is more efficient to do: > > 1. > <option value="1"<?php if($th_order==1){echo " SELECTED"; } > ?>>Something1</option> > <option value="2"<?php if($th_order==2){echo " SELECTED"; } > ?>>Something2</option> > > (or) > > 2. > instead of having the <?php and ?> mixed in the HTML is it better to > echo/print the whole lines? Use a template engine to separate your presentation from your logic. :) -- ---John Holmes... Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/ php|architect: The Magazine for PHP Professionals – www.phparch.com |
|
|||
|
> which is more efficient to do:
> 1. > <option value="1"<?php if($th_order==1){echo " SELECTED"; } > ?>>Something1</option> > <option value="2"<?php if($th_order==2){echo " SELECTED"; } > ?>>Something2</option> > (or) > 2. > instead of having the <?php and ?> mixed in the HTML is it better to > echo/print the whole lines? Really just a matter of personal preference. If I have a mostly PHP page, I would use echo to print out chunks of HTML. If I have a mostly HTML page (or section of a page), I would use separate <?php ?> sections within it. I doubt you'd notice any performance difference between the two so use whichever is easier for you to code. Larry |
|
|||
|
--- "John W. Holmes" <holmes072000@charter.net> wrote:
> Use a template engine to separate your presentation from your logic. :) Isn't PHP a templating engine? :-) Chris ===== My Blog http://shiflett.org/ HTTP Developer's Handbook http://httphandbook.org/ RAMP Training Courses http://www.nyphp.org/ramp |
|
|||
|
Chris Shiflett wrote:
> --- "John W. Holmes" <holmes072000@charter.net> wrote: > >>Use a template engine to separate your presentation from your logic. :) > > > Isn't PHP a templating engine? :-) Of course it is, but what's that got to do with separating presentation from logic (business logic)? Each one can be PHP code... :) Bad answer, I know, because his code could be a PHP "template". I'm sure it's not, though. I just wanted to give a different answer from the many "it doesn't matter" answers. -- ---John Holmes... Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/ php|architect: The Magazine for PHP Professionals – www.phparch.com |
|
|||
|
I'll just on the template bandwagon, I use smarty. (http://smarty.php.net)
Rolf Brusletto phpExamples.net John W. Holmes wrote: > Ryan A wrote: > >> I have an option box on a webpage and have around 10 options on it >> and have >> run into a doubt, >> which is more efficient to do: >> >> 1. >> <option value="1"<?php if($th_order==1){echo " SELECTED"; } >> ?>>Something1</option> >> <option value="2"<?php if($th_order==2){echo " SELECTED"; } >> ?>>Something2</option> >> >> (or) >> >> 2. >> instead of having the <?php and ?> mixed in the HTML is it better to >> echo/print the whole lines? > > > Use a template engine to separate your presentation from your logic. :) > |
|
|||
|
I believe I read someplace once that it is more efficient to have your
php embedded in your HTML where required. Something to do with the amount of parsing that the engine has to do. However, to reiterate what Captain John W. Holmes said, using a templating engine does allow you to better manage the project especially in dealing with maintenance down the road. I personally prefer to let the business logic create XML and employ XSLT to do my Html rendering. It may not be the quickest or most memory efficient, but, in my humble opinion, it is one of the easiest to maintain. Jordan S. Jones Ryan A wrote: >Hi everyone, >Just a simple doubt and basically your opinion needed. > >I have an option box on a webpage and have around 10 options on it and have >run into a doubt, >which is more efficient to do: > >1. ><option value="1"<?php if($th_order==1){echo " SELECTED"; } >?>>Something1</option> ><option value="2"<?php if($th_order==2){echo " SELECTED"; } >?>>Something2</option> > >(or) > >2. >instead of having the <?php and ?> mixed in the HTML is it better to >echo/print the whole lines? > >Thanks, >-Ryan > > > -- I am nothing but a poor boy. Please Donate.. https://www.paypal.com/xclick/busine...rency_code=USD |
|
|||
|
echo/print the whole lines will be faster... but you'll probably not
see the difference... I prefer <?php and ?> mixed in the HTMl because i'm using Dreamweaver to build website/shopping cart/Intranet/Extranet and with the php/HTML mixed, you have a good look about what your webpage will be in the WYSIWYG Dreamweaver Editor window. Regards. Sylvain Giroux Solution Globale Informatique http://www.solutionglobale.com ryan@coinpass.com (Ryan A) wrote in message news:<000b01c39842$871723d0$f081aa51@l2zcaxu7emppq h>... > Hi everyone, > Just a simple doubt and basically your opinion needed. > > I have an option box on a webpage and have around 10 options on it and have > run into a doubt, > which is more efficient to do: > > 1. > <option value="1"<?php if($th_order==1){echo " SELECTED"; } > ?>>Something1</option> > <option value="2"<?php if($th_order==2){echo " SELECTED"; } > ?>>Something2</option> > > (or) > > 2. > instead of having the <?php and ?> mixed in the HTML is it better to > echo/print the whole lines? > > Thanks, > -Ryan |