/    Sign up×
Community /Pin to ProfileBookmark

general question about PHP coding practice

Hi,
I’ve noticed there are two ways to write HTML to a web page.

you can echo the HTML through PHP, for example

echo “<input name=”hiddenTextarea$varincrement” type=”hidden” value=”$maxchars”>”;

or you can just write html and embed the php

<td width=”40″><?php echo $row_Recordset1[‘PDF_KEY_PRODUCT’]; ?></td>

which is the best way? I’ve noticed that books tend to use the former, but wont the former take longer as it has to go through the php engine? and also by using the former programs like dreamweaver dont understand it?

to post a comment
PHP

22 Comments(s)

Copy linkTweet thisAlerts:
@pyroDec 11.2003 — It depends what you are trying to do. If you only have a little HTML to output, it is generally easier to just use an echo statement. If you have more than a little, I would use the latter, as it is indeed easier to type/read.
Copy linkTweet thisAlerts:
@ZibingsDec 12.2003 — Agreed Pyro, though you forgot to mention that Dreamheaver is icky. ?
Copy linkTweet thisAlerts:
@clairec666Dec 12.2003 — Is there anything wrong with saving your PHP files as .html, and getting your server to treat them as PHP files? I've done this for the 'input message' page in my forum, but will this cause any major problem?
Copy linkTweet thisAlerts:
@ZibingsDec 12.2003 — Only problem it would cause is that every .html page, regardless of whether or not it has PHP in it, will be run through the parsing engine. Not usually a big deal unles you have a very very high-traffic site.
Copy linkTweet thisAlerts:
@ZibingsDec 12.2003 — In all honesty, I used to do that with new extensions just for the fun of it, so people would try to figure out what coding language it was. So fun!
Copy linkTweet thisAlerts:
@clairec666Dec 12.2003 — Ah, that'll be alright for the moment then! I have very low traffic - I'm only using localhost on my computer at the moment. But would this delay download time for all my HTML files?
Copy linkTweet thisAlerts:
@ZibingsDec 12.2003 — No, not that YOU view, it's all server-side parsing, so only pages that you are hosting will be parsed, and the chances of you being able to see the difference are pretty slim thanks to the wonderful beautiful Zend Engine.
Copy linkTweet thisAlerts:
@clairec666Dec 12.2003 — Ah. I'm pretty new to server-side stuff. Can I ask something else? I have a MySQL database with a few columns (name, date of birth, height, country etc.) and I want to load all of the names into a JavaScript array, and all the heights into a separate array, etc. and I'm using onclick and innerHTML to display the relevant information from the database. How would I load the MySQL info into the arrays? Should I use echo() to input a script section into the page along with all the arrya items
Copy linkTweet thisAlerts:
@ZibingsDec 12.2003 — Yes! You should, here's an example with a dynamic JavaScript calculator I wrote for Zeropings.com Hosting. (And...by golly, I spent a lot of effort making it easy to customize on their own, and go figure, they just don't figure it out!)

[code=php]
for ( $i = 0; $i < count($ptypes->array); $i++ )
{?>
var <?php echo ( $ptypes->array[$i]['tag'] . "_months" ); ?> = form.<?php echo ( $ptypes->array[$i]['tag'] . "_months" ); ?>.value;<?php
echo ( "n" );
}
[/code]


Now, obviously not the most beautiful piece of code, but it'll give you a little bit of a hint on how to do it. I had problems with the JavaScript code parsing correctly other ways...but...I was working on an IIS server with a default PHP confiuration, so who knows what was wrong. ?
Copy linkTweet thisAlerts:
@clairec666Dec 12.2003 — ? Sorry - another question. :rolleyes: I'll shut up in a minute, honestly. And cheers for the help on the last problem, I'll try it out later.

I used a server-side include (PHP) to include a slideshow into all of my pages. The picture is supposed to change every second, but when I used it as an include, it wasn't changing. I don't have the code with me to post it here, but can you point me in the right direction - is there a problem with Javascript and includes, or is it just a problem with my code?

Cheers
Copy linkTweet thisAlerts:
@ZibingsDec 12.2003 — Why in the world would you have to shut up?! That's what these forums are for (so far as I can tell). Share knowledge and be merry! Oh, and bash on Microsoft as often as possible. *nods*


Seriously though, I just used something like that myself. You can actually have use a <script src='something.php' language='JavaScript' type='text/javascript'></script>. MAKE SURE YOU SPECIFY TYPE AND LANGUAGE. That's what I had to do at least to get it to work...but then I decided to add .js as a PHP MIME type, so...I just put the PHP in my .js files now. ? Hope this helps, and keep asking questions!
Copy linkTweet thisAlerts:
@clairec666Dec 12.2003 — Believe me, I will NEVER shut up! ?

But I'll have to for the time being, since I'm looging off now. ? Cheers for all the help, I'll be back when I need any more

Claire
Copy linkTweet thisAlerts:
@pyroDec 12.2003 — Let me hit a few of these...

[i]Originally posted by Zibings [/i]

[B]Agreed Pyro, though you forgot to mention that Dreamheaver is icky. ? [/B][/QUOTE]
Dreamweaver MX2k4 rocks. It's intelleText and syntax highlighting makes it an excellent tool to use for PHP. As for it's WYSIWYG, it's getting better, but I prefer to hard code my sites...

[i]Originally posted by clairec666[/i]

[b]Is there anything wrong with saving your PHP files as .html, and getting your server to treat them as PHP files?[/b][/quote]
Portability. I would only give my PHP files a .htm or .html (or anything else) extention if it was absolutly necessary.

[i]Originally posted by Zibings [/i]

[B]MAKE SURE YOU SPECIFY TYPE AND LANGUAGE[/B][/QUOTE]
The language attribute was depreciated in 1997. The type attribute is what you want.
Copy linkTweet thisAlerts:
@ZibingsDec 12.2003 — Well Pyro, I still think Dreamweaver isn't good. I use EditPad Pro, it's like Notepad on crack. http://www.editpadpro.com/ I'd suggest it, especially if you like to hard-code, though, you say you like "intelliText". I am making my own in C++ that'll have code explorer functionality like Visual C++, but, I've found a program called PHP Expert Editor that has already done it. If they make it so that it reads all open files in a project like VC++, I will seriously consider switching from EditPad Pro to that. BUT! I'm crazy, as we've already decided, so don't listen to me!
Copy linkTweet thisAlerts:
@damon2003authorDec 12.2003 — but dreamweaver is really good at designing sites where you have to layout a lot of complex tables
Copy linkTweet thisAlerts:
@ZibingsDec 12.2003 — Well, I guess for some it is, but I am a firm believer that well-formatted code can reveal it's secrets easily to anyone. If you can read it, then you can figure out what it's doing.
Copy linkTweet thisAlerts:
@pyroDec 12.2003 — Also, one should not be using tables for layout, much less "complex tables". I assume you mean nested tables, which is a grevious (X)HTML sin...
Copy linkTweet thisAlerts:
@damon2003authorDec 12.2003 — what should you be using?
Copy linkTweet thisAlerts:
@pyroDec 12.2003 — Structural (X)HTML for markup with CSS for layout/presentation. Divisions (<div>) are useful, to be able to divide your pages, and thus group and position things as you want.
Copy linkTweet thisAlerts:
@damon2003authorDec 12.2003 — is css layout well supported?
Copy linkTweet thisAlerts:
@pyroDec 12.2003 — Yes, in most of the popular browsers, CSS layouts will work fine. If coded correctly, all content will continue to be accessible when for the ones that do not (legacy browsers, such as NN 4). Out of all modern day browsers, IE has the worst support for CSS, but can generally be hacked into submission.
Copy linkTweet thisAlerts:
@ZibingsDec 12.2003 — Haha...that's great... "hacked into submission" I like it pyro! Pyro, you and I should create a website, a point counter-point standards guide. *nods* ?
×

Success!

Help @damon2003 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...