Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 5 of 5
  1. #1
    Junior Member
    Join Date
    Feb 2006
    Posts
    12
    Member #
    12651
    I was just wondering if it correct to close php tags even though you opened an if or something and then open new php brackets and close the if, an exmaple is

    PHP Code:
    <?php

    if( ) {

    ?>

    <h1>1 is the answer</h1>

    <?php
    } else {

    ?>
    <h1>2 is the answer</h1>
    <?php

    }
    ?>
    It works fine, but is it bad coding?

  2.  

  3. #2
    Senior Member
    Join Date
    May 2003
    Location
    UK
    Posts
    2,354
    Member #
    1326
    No, that is good coding, that method is found a lot when interacting with a database, such as using a while loop to extract rows from the database table.

  4. #3
    Senior Member jbagley's Avatar
    Join Date
    Sep 2004
    Location
    Cape Town
    Posts
    845
    Member #
    7422
    There are always alternatives to what you have done there. For example:
    PHP Code:
    <?php

    if( ) {
    echo 
    "<h1>1 is the answer</h1>"
    } else {
    echo 
    "<h1>2 is the answer</h1>"
    }
    ?>
    Saves you a couple of lines of code. :classic:

  5. #4
    WDF Staff Wired's Avatar
    Join Date
    Apr 2003
    Posts
    7,656
    Member #
    1234
    Liked
    137 times
    I'd recommend the way cheat does it, as in a fancy editor, it will color code stuff for you in the HTML, and I really hate doing all those damned echo codes.
    The Rules
    Was another WDF member's post helpful? Click the like button below the post.

    Admin at houseofhelp.com

  6. #5
    Junior Member
    Join Date
    Feb 2006
    Posts
    12
    Member #
    12651
    Thanks for the replies, I saw in some php examples the other day and I didn't know it was possible. It helps a lot with databases and tables, as Wired said.


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 07:30 AM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com