Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Nov 2007
    Location
    Leeds, UK
    Posts
    514
    Thanks
    24
    Thanked 19 Times in 19 Posts

    This is Not a HELP Request But INFO Some times simple is better

    in some post i see people echo "(HTML code)"
    E.G.
    PHP 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
    PHP Code:
    i see people inlude("SQLConnect.php");
    function ....
    {
    ...
    ...
    ...
    }
    it is easter to load the SQLCONNECT in the function
    E.G
    function adduser()
    {
    incude("SQLConnect.php");
    ...
    ...
    ...

    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
    Last edited by barkermn01; 11-16-2007 at 01:14 PM.

  • #2
    New to the CF scene
    Join Date
    Aug 2007
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts
    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.

  • #3
    Senior Coder
    Join Date
    Jan 2007
    Posts
    1,648
    Thanks
    1
    Thanked 58 Times in 54 Posts
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •