473,387 Members | 1,569 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Question on style

I come from a corporate C background and I find style to be important in
readability. Especially when multiple people are working on the same code.
I have seen 3 way to deal with large bocks of static HTML code in PHP. What
are your preferences? I have listed the techniques in the order of my
preference.

Hope I don't start an argument ;)

Mark C
Method 1:

switch ($_POST[Mode])
{
case "":
?>
<br><span class='instruct'>Select the area you need to administer.</span>
<form action="Admin.php" method="post">
<input type="submit" name="Mode" value="User">
</form>
<form action="Admin.php" method="post">
<input type="submit" name="Mode" value="Church">
</form>
<form action="Admin.php" method="post">
<input type="submit" name="Mode" value="Ministry">
</form>
<?php
break;

case "User":
$hits = GetEMailList($mn[MinistryID]);

================================================== ====

Method 2:

switch ($_POST[Mode])
{
case "":

print "<br><span class='instruct'>Select the area you need to
administer.</span>";
print "<form action=\"Admin.php\" method=\"post\">";
print " <input type=\"submit\" name=\"Mode\" value=\"User\">";
print "</form>";
print "<form action=\"Admin.php" method="post">";
print " <input type=\"submit" name="Mode" value="Church">";
print "</form>";
print "<form action=\"Admin.php\" method=\"post\">";
print " <input type=\"submit\" name=\"Mode\" value=\"Ministry\">";
print "</form>";
break;

case "User":
$hits = GetEMailList($mn[MinistryID]);

================================================== ====

Method 3:

switch ($_POST[Mode])
{
case "":

$Var = <<<EOQ
<br><span class='instruct'>Select the area you need to administer.</span>
<form action="Admin.php" method="post">
<input type="submit" name="Mode" value="User">
</form>
<form action="Admin.php" method="post">
<input type="submit" name="Mode" value="Church">
</form>
<form action="Admin.php" method="post">
<input type="submit" name="Mode" value="Ministry">
</form>
EOQ;

print $Var;
break;

case "User":
$hits = GetEMailList($mn[MinistryID]);
Jul 17 '05 #1
6 1659
Hi Mark.
Method 1:
switch ($_POST[Mode])
{
case "":
?>
<br><span class='instruct'>Select the area you need to administer.</span>
<snip...> </form>
<?php
break;

case "User":
$hits = GetEMailList($mn[MinistryID]);

I'd go with method 1. Main reason for choosing is that its far more
effecient. Not having to echo/print statid HTML can save ya a lot of CPU
time.

Just my $0.02...

--
Swartz

Jul 17 '05 #2
"Mark C" <no****@today.com> wrote in message
news:<10*************@corp.supernews.com>...

I come from a corporate C background
Then you probably understand the difference between a constant (Mode)
and a literal ('Mode') and should stop using $_POST[Mode] and switch
to $_POST['Mode'].
and I find style to be important in readability.
Unfortunately, readable code is not necessarily the best-performing
code...
I have seen 3 way to deal with large bocks of static HTML code in PHP.
What are your preferences?


None of the three you suggest. It is usually considered a good idea
to separate logic from content. So my preference would be to define
the long block of static HTML elsewhere and display it when needed
via include() or even readfile(). But then, again, that would be
my personal preference, stemming from aesthetics, not performance
testing. So here goes:

Method 4:

switch ($_POST['Mode']) {
case '':
include ('form.php'); // the idea being, HTML code for the form
echo $form; // is defined as variable $form in form.php
break;
case 'User':
$hits = GetEMailList($mn['MinistryID']);
}

Method 5:

switch ($_POST['Mode']) {
case '':
readfile ('form.htm'); // the idea being, HTML code for the form
// is contained in file form.htm
break;
case 'User':
$hits = GetEMailList($mn['MinistryID']);
}

It is also usually considered a good idea to conceal form.* file
by putting it into a directory outside the document root or into
a restricted-access directory protected with .htaccess.

Cheers,
NC
Jul 17 '05 #3
Yes...

I have been using method 1 for along time and I dont like it at all. Its a
pig of a way to do things. Including the html is much better. You can store
"hook" in the html so it can be a bit dynamic. EG <title>%TITLE%</title>.

I find this is alot better to work with, you can edit the html in an editor
like Dreamweaver and use PHPed or something similer to edit the php...

I also use a class called page that renders a html page... maybe something
else to think about?

Just my 0.02c :P

"Nikolai Chuvakhin" <nc@iname.com> wrote in message
news:32**************************@posting.google.c om...
"Mark C" <no****@today.com> wrote in message
news:<10*************@corp.supernews.com>...

I come from a corporate C background


Then you probably understand the difference between a constant (Mode)
and a literal ('Mode') and should stop using $_POST[Mode] and switch
to $_POST['Mode'].
and I find style to be important in readability.


Unfortunately, readable code is not necessarily the best-performing
code...
I have seen 3 way to deal with large bocks of static HTML code in PHP.
What are your preferences?


None of the three you suggest. It is usually considered a good idea
to separate logic from content. So my preference would be to define
the long block of static HTML elsewhere and display it when needed
via include() or even readfile(). But then, again, that would be
my personal preference, stemming from aesthetics, not performance
testing. So here goes:

Method 4:

switch ($_POST['Mode']) {
case '':
include ('form.php'); // the idea being, HTML code for the form
echo $form; // is defined as variable $form in form.php
break;
case 'User':
$hits = GetEMailList($mn['MinistryID']);
}

Method 5:

switch ($_POST['Mode']) {
case '':
readfile ('form.htm'); // the idea being, HTML code for the form
// is contained in file form.htm
break;
case 'User':
$hits = GetEMailList($mn['MinistryID']);
}

It is also usually considered a good idea to conceal form.* file
by putting it into a directory outside the document root or into
a restricted-access directory protected with .htaccess.

Cheers,
NC

Jul 17 '05 #4

"Nikolai Chuvakhin" <nc@iname.com> wrote in message
news:32**************************@posting.google.c om...
"Mark C" <no****@today.com> wrote in message
news:<10*************@corp.supernews.com>...

I come from a corporate C background
Then you probably understand the difference between a constant (Mode)
and a literal ('Mode') and should stop using $_POST[Mode] and switch
to $_POST['Mode'].


I had seen the different syntax, but none of the texts I have indicated the
difference. Sinice it worked either way I assumed there was no difference.
But as I think about all the thing you can put in the [] I see how the ' can
help the interpterter.

I have seen 3 way to deal with large bocks of static HTML code in PHP.
What are your preferences?


None of the three you suggest. It is usually considered a good idea
to separate logic from content. So my preference would be to define
the long block of static HTML elsewhere and display it when needed
via include() or even readfile(). But then, again, that would be
my personal preference, stemming from aesthetics, not performance
testing. So here goes:

Method 4:

switch ($_POST['Mode']) {
case '':
include ('form.php'); // the idea being, HTML code for the form
echo $form; // is defined as variable $form in form.php
break;
case 'User':
$hits = GetEMailList($mn['MinistryID']);
}

Method 5:

switch ($_POST['Mode']) {
case '':
readfile ('form.htm'); // the idea being, HTML code for the form
// is contained in file form.htm
break;
case 'User':
$hits = GetEMailList($mn['MinistryID']);
}


I like both these ideas. I did not think of either right off the top of my
head. I would have to get used to looking to another document for content.
I generaly try to put logic in functions and classes and keep the main page
more output oriatned with calls to libraries for number crunching.

Good discussion,

Mark C
Jul 17 '05 #5
"Mark C" <no****@today.com> wrote in message
news:10*************@corp.supernews.com...
I come from a corporate C background and I find style to be important in
readability. Especially when multiple people are working on the same code. I have seen 3 way to deal with large bocks of static HTML code in PHP. What are your preferences? I have listed the techniques in the order of my
preference.

Hope I don't start an argument ;)

Mark C
Method 1:

switch ($_POST[Mode])
{
case "":
?>
<br><span class='instruct'>Select the area you need to administer.</span> <form action="Admin.php" method="post">
<input type="submit" name="Mode" value="User">
</form>
<form action="Admin.php" method="post">
<input type="submit" name="Mode" value="Church">
</form>
<form action="Admin.php" method="post">
<input type="submit" name="Mode" value="Ministry">
</form>
<?php
break;

case "User":
$hits = GetEMailList($mn[MinistryID]);

================================================== ====

Method 2:

switch ($_POST[Mode])
{
case "":

print "<br><span class='instruct'>Select the area you need to
administer.</span>";
print "<form action=\"Admin.php\" method=\"post\">";
print " <input type=\"submit\" name=\"Mode\" value=\"User\">";
print "</form>";
print "<form action=\"Admin.php" method="post">";
print " <input type=\"submit" name="Mode" value="Church">";
print "</form>";
print "<form action=\"Admin.php\" method=\"post\">";
print " <input type=\"submit\" name=\"Mode\" value=\"Ministry\">";
print "</form>";
break;

case "User":
$hits = GetEMailList($mn[MinistryID]);

================================================== ====

Method 3:

switch ($_POST[Mode])
{
case "":

$Var = <<<EOQ
<br><span class='instruct'>Select the area you need to administer.</span> <form action="Admin.php" method="post">
<input type="submit" name="Mode" value="User">
</form>
<form action="Admin.php" method="post">
<input type="submit" name="Mode" value="Church">
</form>
<form action="Admin.php" method="post">
<input type="submit" name="Mode" value="Ministry">
</form>
EOQ;

print $Var;
break;

case "User":
$hits = GetEMailList($mn[MinistryID]);


Well, you know what they say about opionion, they are like... well, lets
just say everyone has one. :)

I can warrent times when you would need to do all the 3 you listed above.
method 1: if you needed to edit the html section in say, dreamweaver.
method 2: if you jsut need to spit out a couple lines
method 3: if the block has vars in it, but I would do print <<< instead of
$var <<<
method 4: method 1, as was stated by someone else, put html in a seperate
file, use to keep site very dynamic

just my 1 cent, need other 1 cent for another post

--
Mike Bradley
http://www.gzentools.com -- free online php tools
Jul 17 '05 #6
Mark C wrote:

"Nikolai Chuvakhin" <nc@iname.com> wrote in message
news:32**************************@posting.google.c om...

Then you probably understand the difference between a constant (Mode)
and a literal ('Mode') and should stop using $_POST[Mode] and switch
to $_POST['Mode'].


I had seen the different syntax, but none of the texts I have indicated the
difference. Sinice it worked either way I assumed there was no difference.
But as I think about all the thing you can put in the [] I see how the ' can
help the interpterter.


If you enable all errors, warnings, and notices (as you should, at
least, while developing the script) you'll get a notice for using
undefined constants.

<?php
error_reporting(E_ALL);

define('Mode2', 'something');

echo 'Mode'; // OK
echo Mode; // Notice: Use of undefined constant Mode - assumed 'Mode'

echo 'Mode2'; // OK
echo Mode2; // OK; prints "something"
?>
--
--= my mail box only accepts =--
--= Content-Type: text/plain =--
--= Size below 10001 bytes =--
Jul 17 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: HolaGoogle | last post by:
hi there, i've 2 questions for you guys.... 1: is there any way to "force" a session_onend(), session timeout or at least call my logout method when a user leaves the application window without...
19
by: CMAR | last post by:
I have the following markup. The problem is that the browser, e.g., IE6, inserts several lines of blank space between the <div> and the following table. Is there a way to minimize that vertical...
7
by: Sharon | last post by:
Hiya I have a small question, I saw this piece of code somewhere (it's for creating a customized context menu) and I was wondering: Why is it that the STYLE and SCRIPT-tags are broken up into...
4
by: Nigel Molesworth | last post by:
I've Googled, but can't find what I need, perhaps I asking the wrong question! I want a "FAQ" page on a web site, I hate those pages that scroll you to the answer so and I figured that a good...
1
by: amerar | last post by:
Hi All, I posted a question about style sheets, and why certain email clients were ignoring them. Someone suggested placing them inline. I did this and get better results, but not what I...
8
by: George | last post by:
I need help with the code listed below. See the line below the comment-// *** This displays the error *** I want to be able to have the event handler call the function based on the reference...
2
by: Robert Smith jr. | last post by:
Hello, Please pardon my newbie question ... I am building an ASP.NET page that displays a recordset with a Delete statement enabled (this all works fine). I want to Insert the current row...
5
by: | last post by:
I want to define a style that automatically associates a specific image with certain IMG elements. Is there a way to do this with ASP.NET? If I use an ASP.NET image control and specify a class...
2
by: Ken Fine | last post by:
I want to add the security question and answer security feature to the ChangePassword control. I am aware that this functionality is built into the PasswordRecovery tool. I have implemented the...
25
by: bonneylake | last post by:
Hey Everyone, Well i am not sure if my question needs to be here or in coldfusion. If i have my question is in the wrong section i am sorry in advance an will move it to the correct section. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.