wrathican Posted August 3, 2007 Share Posted August 3, 2007 Ive created this poll to see what is the most common/best way to do it... i personally do it like this: <ul> <?php include './include/misc.inc'; include './include/opendb.inc'; $query = "SELECT * FROM port_section"; $result = mysql_query($query); while($row = mysql_fetch_array($result,MYSQL_NUM)) { $sect = $row[1]; $title = $row[2]; ?> <li><a href="?func=views&cat=<?php echo $sect; ?>"><?php echo $title; ?></a></li> <?php } ?> </ul> whihch is the most effcient way? Quote Link to comment Share on other sites More sharing options...
zq29 Posted August 3, 2007 Share Posted August 3, 2007 Depends on how much HTML I need to echo, if it's just a couple of lines I just echo it, if there is more HTML than there is PHP, I jump in and out of the PHP. Quote Link to comment Share on other sites More sharing options...
Daniel0 Posted August 3, 2007 Share Posted August 3, 2007 I use echo. If it's large amounts of HTML (or other data) I need to echo, then I use heredoc. Shouldn't this be in "Polls" by the way? Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted August 3, 2007 Share Posted August 3, 2007 Same as SA for me. Never use the heredoc syntax - not really sure why, just prefer the other methods. Quote Link to comment Share on other sites More sharing options...
akitchin Posted August 3, 2007 Share Posted August 3, 2007 i use heredoc syntax for long bits of HTML that i want to allow designers to edit without having to worry about syntactical issues (like for e-mail messages that use POST variables, etc.). i mainly listen to music while programming, to answer the title question properly. Quote Link to comment Share on other sites More sharing options...
tibberous Posted August 4, 2007 Share Posted August 4, 2007 I think both would be the most common answer, no one can just never echo html. I'd bet a bunch of people don't know how to shut php on and off for conditional output - I had a partner in college who kept saying that I saw going to get an error about missing a brace =P Quote Link to comment Share on other sites More sharing options...
Gho§t Posted August 13, 2007 Share Posted August 13, 2007 Neither. I tend to use a template engine in most of my projects. In very small projects though, I would be in the "echo small, heredoc big" group. Quote Link to comment Share on other sites More sharing options...
NArc0t1c Posted August 19, 2007 Share Posted August 19, 2007 I use echo, except when there are single and double quotes, then I would consider heredoc. Quote Link to comment Share on other sites More sharing options...
TheFilmGod Posted August 31, 2007 Share Posted August 31, 2007 I use echo, except when there are single and double quotes, then I would consider heredoc. You can escape the double and single quotes easily. All you do is Edit --> Find and Replace --> Find (") Replace (\"). Not hard. I don't see the point of using a heredoc, while escaping the quotes is faster and more effiecient. Quote Link to comment Share on other sites More sharing options...
Daniel0 Posted August 31, 2007 Share Posted August 31, 2007 I use echo, except when there are single and double quotes, then I would consider heredoc. You can escape the double and single quotes easily. All you do is Edit --> Find and Replace --> Find (") Replace (\"). Not hard. I don't see the point of using a heredoc, while escaping the quotes is faster and more effiecient. I don't think it's more efficient? Do you have any sources to verify that? It'll also make your code uglier and harder to read if you have escaped characters in all your strings. Quote Link to comment Share on other sites More sharing options...
roopurt18 Posted August 31, 2007 Share Posted August 31, 2007 while escaping the quotes is faster and more effiecient. Unless you're running Google, Yahoo, YouTube, MySpace, etc. then the performance gained by such a "tweak" would be almost negligible. The process for programming web pages which interact with a database should always, IMO, be: 1) Write your code such that it is readable and maintainable 2) Execute your code in a real world environment, with real data 3) Monitor your page load times, if a page loads slowly do the following: 3a) Check all of your queries being executed, update DB indexes as appropriate 3b) Make any changes to actual code next, typically in the form of refactoring or modifying your algorithm / process 4) Build your site such that you can turn on performance logging. When this feature is enabled you're site should notify you of any page or query that takes longer than X seconds to load or execute. This will help you spend your time optimizing code where it is needed. Quote Link to comment Share on other sites More sharing options...
markjoe Posted September 1, 2007 Share Posted September 1, 2007 I make it a point to have separate php, html, and js (javascript) files. Although, I do mostly high function stuff easy on the 'pretty'. So not a whole lot of HTML to worry about. Still, if I need to stick a lot of HTML in the middle of php code, I would include it from external file. .php files are only php code, .js files are only javascript, and so on. Quote Link to comment Share on other sites More sharing options...
Azu Posted September 4, 2007 Share Posted September 4, 2007 Ive created this poll to see what is the most common/best way to do it... i personally do it like this: <ul> <?php include './include/misc.inc'; include './include/opendb.inc'; $query = "SELECT * FROM port_section"; $result = mysql_query($query); while($row = mysql_fetch_array($result,MYSQL_NUM)) { $sect = $row[1]; $title = $row[2]; ?> <li><a href="?func=views&cat=<?php echo $sect; ?>"><?php echo $title; ?></a></li> <?php } ?> </ul> whihch is the most effcient way? echo Quote Link to comment Share on other sites More sharing options...
neylitalo Posted September 4, 2007 Share Posted September 4, 2007 I changed the original post title. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.