order of execution of code

Discussion in 'PHP' started by billybrag, Oct 12, 2006.

  1. #1
    Wierd question perhaps, but is there a wa that i can play with the order that code is executed as I have an include halfway down which i need to leave in place - but i also need it to update something in the header of the page, which currently does not work. I have tried moving said code below the include and it works fine - any ideas?
     
    billybrag, Oct 12, 2006 IP
  2. alemcherry

    alemcherry Guest

    Best Answers:
    0
    #2
    Code is executed from top to bottom. You may have to include somethign before it is being used. Or use some trick like changing the DIV content by dynamically generating the javascript.

    Its all about understanding the basics and applying the logic. Hard to give detailed suggestion, I am tempted to ask more questions rather! As a suggestion, you may spend some more time for planning.
     
    alemcherry, Oct 12, 2006 IP
  3. billybrag

    billybrag Peon

    Messages:
    324
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #3
    hmm, thanks.

    though plannning still led to this problem - its not always possible to spot all problems on the horizon
     
    billybrag, Oct 12, 2006 IP
  4. clancey

    clancey Peon

    Messages:
    1,099
    Likes Received:
    63
    Best Answers:
    0
    Trophy Points:
    0
    #4
    I still try to follow the principles I learned coding C.

    All includes are at the top of the file. Any data needed by functions is explicitly passed to it and results from the function explicitly returned.

    Using this approach in PHP solves the problem of includes needing to be in multiple places to satisfy multiple needs. This also ensures data needed for each function is given to it in a way that lets the function manipulate the data without affecting other parts of the program -- ie, resetting the value to something unexpected!
     
    clancey, Oct 12, 2006 IP
  5. Barti1987

    Barti1987 Well-Known Member

    Messages:
    2,703
    Likes Received:
    115
    Best Answers:
    0
    Trophy Points:
    185
    #5
    you could do that using:

    
    ob_start();
    echo header info;
    $holdit = ob_get_contents();
    ob_end_clean();
    
    echo second stuff
    echo $holdit;
    
    PHP:
    is this what you need?

    Peace,
     
    Barti1987, Oct 12, 2006 IP