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 4 of 4
  1. #1
    Regular Coder
    Join Date
    Jul 2005
    Posts
    131
    Thanks
    21
    Thanked 0 Times in 0 Posts

    compile data to show later?

    I havent a clue how to describe it, so yeah the title doesnt make much sense

    As im pulling data out of a db and running a loop, is there any way i can basically store some of that information in a formatted capacity, and then display it later down the line, rather than having to display it at the point the script is at??

    For example, can i store and output html with a variable?

    I was hoping that i could use something along the lines of
    PHP Code:
    $table = include("header.php");
    while (
    blabla)
    {
    $table .= include("body.php");
    }
    $table .= include("footer.php");
    echo 
    $table_name
    However, it automatically displays the contents which makes it useless to me, and i dont know of anything which would basically pull the contents of a file and store it within the variable, to then be able to output when required.

    Is there something? I could probably do what i need in this instance with an array (i really hate them!) but there has been times when i've wanted to to be able to build stuff as im pulling info, but not wanting it to be displayed there & then and often thought it'd be handy.
    Last edited by PaulC2K; 09-12-2013 at 12:43 AM.

  • #2
    Regular Coder
    Join Date
    Jul 2005
    Posts
    131
    Thanks
    21
    Thanked 0 Times in 0 Posts
    Just marked it resolved cos i thought file_get_contents was going to save the day, but it isnt populating the contents php as i'd thought it was going to.

    the contents of body.php for example, would be $myrow['Name'] | $myrow['Value'] or whatever, so i need it to read and interact with the contents, but not take that to mean display it right now.
    Last edited by PaulC2K; 09-12-2013 at 12:46 AM.

  • #3
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    3,762
    Thanks
    23
    Thanked 548 Times in 547 Posts
    You can pass PHP variables to Javascript and then display them at a later time or when an event takes place.
    PHP Code:
    <?php
    $ducky 
    "Love is all around.";
    do 
    stuff here
    ?>
     
    <html>
    <head>
    <script>
    var phpstring = <?php echo $ducky?>;
    </script>
    </head>
    <body>......
    Now your in your HTML page and the JS var named phpstring is "Love is all around." and that can be printed out to the page any time you'd like.
    Evolution - The non-random survival of random variants.

  • Users who have thanked sunfighter for this post:

    PaulC2K (09-12-2013)

  • #4
    Regular Coder Arcticwarrio's Avatar
    Join Date
    May 2012
    Location
    UK
    Posts
    709
    Thanks
    20
    Thanked 84 Times in 84 Posts
    in the 3 files:
    header.php
    body.php
    footer.php

    instead of echoing things set them into variables:

    PHP Code:
    <?PHP
    $Head 
    '';
    $Head .= '<html>
    <head>
    <title>title</title>
    </head>'
    ;
    //etc
    ?>
    and in your main page

    PHP Code:
    include("header.php");
    include(
    "body.php");
    include(
    "footer.php");


    echo 
    $Head;

    // do stuff

    echo $Body;

    //other stuff

    echo $Footer
    There are 10 types of people on CodingForums,
    Those who understand Binary and those who dont.
    Get Cloud Hosting now from only£59 / month

  • Users who have thanked Arcticwarrio for this post:

    PaulC2K (09-12-2013)


  •  

    Posting Permissions

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