hosted by liquidweb


Go Back   Web Hosting Talk : Web Hosting Main Forums : Programming Discussion : which is best coding?
Reply

Programming Discussion Discussions related to web programming languages and other related issues. Topics may include configuration, optimization, practical usage and database connectivity.
Forum Jump

which is best coding?

Reply Post New Thread In Programming Discussion Subscription
 
Send news tip View All Posts Thread Tools Search this Thread Display Modes
  #1  
Old 09-11-2002, 01:09 PM
PortalMelt PortalMelt is offline
New Member
 
Join Date: Sep 2002
Location: Jacksonville, Florida - USA
Posts: 3

which is best coding?


Which is Best Coding?
Each of these sets of code will produce the same results in the display.

Question: When carried out in a large application, which is better? Is there a performance difference in the two different methods?

The benefit of the first one is that I can control all of the display (the HTML) in Dreamweaver and actually see what I'm doing, but I wonder if there is a performance hit or some other problem.

Thanks for your insights.
Comments please.
Jeff


PHP Code:
<table width="100%" border="1" cellspacing="0" cellpadding="0"> 
  <tr> 
    <td><?php echo $item1?></td> 
    <td><?php echo $item2?></td> 
    <td><?php echo $item3?></td> 
  </tr> 
  <tr> 
    <td><?php echo $item4?></td> 
    <td><?php echo $item5?></td> 
    <td><?php echo $item6?></td> 
  </tr> 
</table>
PHP Code:
<?php 
echo "<table width=\"100%\" border=\"1\" cellspacing=\"0\" cellpadding=\"0\">"
    .
"<tr>" 
    
."<td>".$item1."</td>" 
    
."<td>".$item2."</td>" 
    
."<td>".$item3."</td>" 
  
."</tr>" 
  
."<tr>" 
    
."<td>".$item4."</td>" 
    
."<td>".$item5."</td>" 
    
."<td>".$item6."</td>" 
  
."</tr>" 
."</table>"
?>

Reply With Quote


Sponsored Links
  #2  
Old 09-11-2002, 01:15 PM
prosayist prosayist is offline
Junior Guru Wannabe
 
Join Date: Dec 2001
Location: New Hampshire
Posts: 93
actually, I'm not quite sure of the perf diff myself, but I'd be likely to guess that
PHP Code:
<?php 
echo "<table width=\"100%\" border=\"1\" cellspacing=\"0\" cellpadding=\"0\">
       <tr> 
        <td>"
.$item1."</td>
        <td>"
.$item2."</td>
        <td>"
.$item3."</td>
       </tr>
       <tr>
        <td>"
.$item4."</td>
        <td>"
.$item5."</td>
        <td>"
.$item6."</td>
       </tr>
      </table>"

?>
wouldn't cause any parse errors

__________________
WYSIWYG

Reply With Quote
  #3  
Old 09-11-2002, 01:19 PM
PortalMelt PortalMelt is offline
New Member
 
Join Date: Sep 2002
Location: Jacksonville, Florida - USA
Posts: 3
That's true, but not what I was asking.

In my first example, PHP is opened and closed only when needed and not used to echo the html. This leaves the html exposed to Dreamweaver.

In my second example, PHP is opened once and generates everthing. This hides the html from Dreamweaver.

Comments please.
Jeff

Reply With Quote
Sponsored Links
  #4  
Old 09-11-2002, 01:24 PM
Alturus Alturus is offline
Newbie
 
Join Date: Aug 2002
Location: Canada
Posts: 22
The first method is generally accepted as better programming practice.

Reply With Quote
  #5  
Old 09-11-2002, 01:27 PM
prosayist prosayist is offline
Junior Guru Wannabe
 
Join Date: Dec 2001
Location: New Hampshire
Posts: 93
really I understood that, just pointing out a trivial fact [edit: not a 'face'].. sorry for not applying myself to find your answer;
check here -> http://p2p.wrox.com/archive/php_howto/2002-07/28.asp

or here -> http://www.google.com/search?sourcei...%3C%3Fecho+php

__________________
WYSIWYG

Reply With Quote
  #6  
Old 09-11-2002, 01:42 PM
Alturus Alturus is offline
Newbie
 
Join Date: Aug 2002
Location: Canada
Posts: 22
PHP Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html>
<head>
<style type="text/css">
.main {
    text-align: center;
    width: 33%;
    float: left;
    border: 1px solid #000000;
    }
</style>
</head>
<body>


    <div class="main"><? echo $var1?></div>
    <div class="main"><? echo $var2?></div>
    <div class="main"><? echo $var3?></div>

    <div class="main"><? echo $var4?></div>
    <div class="main"><? echo $var5?></div>
    <div class="main"><? echo $var6?></div>


</body>
</html>
Is a little better code : )


But in all seriousness, using PHP to parse a chunk of code (the table tages) will use more processing time than just processing the variable names. Plus it works better for you while using DW.


Last edited by Alturus; 09-11-2002 at 01:47 PM.
Reply With Quote
  #7  
Old 09-11-2002, 01:53 PM
PortalMelt PortalMelt is offline
New Member
 
Join Date: Sep 2002
Location: Jacksonville, Florida - USA
Posts: 3
Thanks.

prosayist: I wasn't mad, just trying to keep things on track. Thanks for the followup answer.

Alturus: Too funny, and yes I realize that. Thanks for the humor and the feedback. This seems to be the concesus I am gettin gin the diff places and people I have asked.


I see A LOT of code done the second way. Makes you go Hmmmm. . .

Reply With Quote
  #8  
Old 09-11-2002, 03:17 PM
Rich2k Rich2k is offline
Web Hosting Master
 
Join Date: May 2002
Location: UK
Posts: 2,994
Quote:
Originally posted by Alturus
PHP Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html>
<head>
<style type="text/css">
.main {
    text-align: center;
    width: 33%;
    float: left;
    border: 1px solid #000000;
    }
</style>
</head>
<body>


    <div class="main"><?= $var1?></div>
    <div class="main"><?= $var2?></div>
    <div class="main"><?= $var3?></div>

    <div class="main"><?= $var4?></div>
    <div class="main"><?= $var5?></div>
    <div class="main"><?= $var6?></div>


</body>
</html>
Actually you could simplify it even further. Personally I don't use short tags like that... but I believe that's the format.

Reply With Quote
  #9  
Old 09-11-2002, 08:58 PM
idlenut idlenut is offline
New Member
 
Join Date: Sep 2002
Location: Toronto, Canada
Posts: 1
PHP Code:
<table width="100%" border="1" cellspacing="0" cellpadding="0"> 
  <tr> 
    <td><?=$item1?></td> 
    <td><?=$item2?></td> 
    <td><?=$item3?></td> 
  </tr> 
  <tr> 
    <td><?=$item4?></td> 
    <td><?=$item5?></td> 
    <td><?=$item6?></td> 
  </tr> 
</table>
that is the shortest way to print variables while jumping in and out of PHP mode

Reply With Quote
  #10  
Old 09-13-2002, 03:45 AM
prosayist prosayist is offline
Junior Guru Wannabe
 
Join Date: Dec 2001
Location: New Hampshire
Posts: 93
.. ya might also look here => http://evolt.org/article/PHP_Guideli...440/index.html

[preview]idlenut's last comment is marginally faster[/preview]

__________________
WYSIWYG

Reply With Quote
Reply

Related posts from TheWhir.com
Title Type Date Posted
CloudMine Launches Cloud Backend-as-a-Service Platform Web Hosting News 2012-06-22 12:04:04
Rackspace Blog Looks at Easy Outsourcing for App Development Blog 2012-03-05 19:07:48
Cloud Host ScaleXtreme Launches Cloud Service Provider Program Web Hosting News 2012-01-31 16:55:10
Web Host Gazzin.com Upgrades Reseller and VPS Plans Web Hosting News 2011-07-29 18:48:35
US-CERT Publishes Recommendations for Preventing Cyber Security Attacks Web Hosting News 2011-07-22 19:07:35


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes
Postbit Selector

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump
Login:
Log in with your username and password
Username:
Password:



Forgot Password?
Advertisement:
Web Hosting News:



 

X

Welcome to WebHostingTalk.com

Create your username to jump into the discussion!

WebHostingTalk.com is the largest, most influentual web hosting community on the Internet. Join us by filling in the form below.


(4 digit year)

Already a member?