1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Some really simple php question

Discussion in 'PHP' started by slaydragon, Jul 25, 2008.

  1. #1
    hi, normally when we do programming. It is best that we get each php file to do different functions right? Like extract.php to extract data, search.php to search for things. In the end, how do you guys normally link those files together? i am using alot of require(); in my index.php file, don't really know if its a best practice.

    Do you guys put all the require() file on the top? i am putting them everywhere in my code when i need it. am i doing the right thing?
     
    slaydragon, Jul 25, 2008 IP
  2. EricBruggema

    EricBruggema Well-Known Member

    Messages:
    1,740
    Likes Received:
    28
    Best Answers:
    13
    Trophy Points:
    175
    #2
    Using require or require_once on the right places can indeed speed up your scripting.. coz it will be only executed when needed.
     
    EricBruggema, Jul 25, 2008 IP
    slaydragon likes this.
  3. slaydragon

    slaydragon Banned

    Messages:
    1,403
    Likes Received:
    24
    Best Answers:
    0
    Trophy Points:
    0
    #3
    when using requires, do you guys only put php functions in it? or even html codings?
     
    slaydragon, Jul 25, 2008 IP
  4. Tamarack

    Tamarack Peon

    Messages:
    48
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    php html - whatever you require

    I think the main difference between an include and require is the error handling
     
    Tamarack, Jul 25, 2008 IP
  5. amitbravo

    amitbravo Banned

    Messages:
    94
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #5
    I give you an example how to do embed the script inside the script

    1. main.php
    <?php
    require("sub.php");
    echo $cal;
    ?>

    2. sub.php
    <?php
    $cal=3+4;
    ?>

    This was a really simple example for a really simple php question.. please remeber if you using:

    1. right syntax
    2. right path ( if sub.php is located in another folder )
    3. using right php tags
    4. correct file name (sub.php)

    if yes, then it should work.
     
    amitbravo, Jul 25, 2008 IP
    slaydragon likes this.