View Full Version : This is Not a HELP Request But INFO Some times simple is better

11-16-2007, 01:32 PM
in some post i see people echo "(HTML code)"

echo'<input type="text" value="use me" name="hello"'>

Why not just

?> //end php
<input type="text" Value="use me" name="Hello">

This has one major good side it is quicker PHP is not loadin alod of HTML for it to echo straight back out ?
ok soem times you have to echo the code coz there are difernt thing you want on one depeding on things setup but
at the end of a php file jut close the php and just send the data as html to the users end
Second one

i see people inlude("SQLConnect.php");
function ....
it is easter to load the SQLCONNECT in the function
function adduser()

One this is eayer to follow 2 people helping can see that you are using SQL Connection and if you ever open your code people can follow easyer insted of forgeting you have opend SQL at the top
and yes again some times this is better say if you have all your SQL functs in one file serperte from the rest but then tell users that are giving u support that it is included coz we cant see that usless we are told by use when we are fixing functions

P.S if you have seen users do some thing that stops people helping coz we dont know what the have loaded Post it and leave it so users can see wht would be good Practise

11-16-2007, 03:55 PM
On the first one with the echo there is a good reason to echo over just closing the php script. Readability. If you ever have to work in a group with a bunch of php developers and you seen some code that keeps opening and closing php scripts and javascript scripts it gets a little confusing and takes a lot more time to understand what's going on sometime. Not a big issue but one that can be considered. As far as including sql connections in functions I agree with your point. But as we know good practice isn't always practiced.

11-16-2007, 05:13 PM
Your first issue is an issue of preference. There is no 'better way', it is about what you prefer.

Your second example is just bad code. You are using include, if you add 2 users in the same page you will either get an error (if the file contains functions) or you will be connecting to the database too many times.

It's more efficient to set up your Database class to do lazy loading, and just have 1 single clean require_once call at the top of your initial page.