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 14 of 14
  1. #1
    New to the CF scene
    Join Date
    Jun 2012
    Posts
    9
    Thanks
    1
    Thanked 0 Times in 0 Posts

    'Help' php echo inside php include

    Hi
    trying to include a echo inside a php include. How would I go about and do that?

    ex:
    Code:
    <?php include 'page.php?aid=<?php echo $id; ?>'; ?>
    Tried many ways haven't got it to work yet. The part I'm stock at to get working is the
    Code:
    <?php echo $id; ?>
    after this ?aid=
    Appreciate any help!

  • #2
    New Coder
    Join Date
    Sep 2007
    Posts
    50
    Thanks
    16
    Thanked 0 Times in 0 Posts
    Why are you trying to that in an include statement?

  • #3
    New to the CF scene
    Join Date
    Jun 2012
    Posts
    9
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by frank727 View Post
    Why are you trying to that in an include statement?
    because trying to include it in a modal box when triggered. Trying something new instead of opening a new page with
    Code:
    <a href="page.php?aid=<?php echo $id;?>"></a>
    which worked but like mentioned trying something new. I wanted to see if can be done.

  • #4
    Regular Coder LearningCoder's Avatar
    Join Date
    Jan 2011
    Location
    The Pleiades
    Posts
    924
    Thanks
    76
    Thanked 29 Times in 29 Posts
    Yup I really can't see why you are trying to include a file and then echo a value within the include statement. If you want to use another file to echo a value, you can do this:
    PHP Code:
    include("page.php?aid=some_value"); 
    THEN, within your page.php script, you can do this:
    PHP Code:
    if(isset($_GET['aid']))
    {
         echo 
    $_GET['aid'];
    }
    else
    {
        echo 
    "$_GET variable not set.";

    OR, do this:
    PHP Code:
    $get = (isset($_GET['aid'])) ? $_GET['aid'] : "$_GET variable not set";

    echo 
    $get
    Does this help at all? Test it out and see what you think.

    Regards,

    LC.

  • Users who have thanked LearningCoder for this post:

    eureka (02-10-2013)

  • #5
    New to the CF scene
    Join Date
    Jun 2012
    Posts
    9
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by LearningCoder View Post
    Yup I really can't see why you are trying to include a file and then echo a value within the include statement. If you want to use another file to echo a value, you can do this:
    PHP Code:
    include("page.php?aid=some_value"); 
    THEN, within your page.php script, you can do this:
    PHP Code:
    if(isset($_GET['aid']))
    {
         echo 
    $_GET['aid'];
    }
    else
    {
        echo 
    "$_GET variable not set.";

    OR, do this:
    PHP Code:
    $get = (isset($_GET['aid'])) ? $_GET['aid'] : "$_GET variable not set";

    echo 
    $get
    Does this help at all? Test it out and see what you think.

    Regards,

    LC.
    Thanks for the help but no it did not work.
    The previous way I had it was in a link
    Code:
    http://www.example.com.page.php?aid=<?php echo $id; ?>
    where $id; would pull the user id from the database and show certain information for that user on a new page ex: url output would have been http://example.com/page.php?aid=234 234 would be for user John D and show his information. Now I'm just trying to open it in a simple modal window by triggering the modal and within the modal body theres a php include of the url so the output would show the same information but I am having the issue of pulling the $id because it is already with <?php ?> and trying echoing the $id within the include only comes blank within the modal box body. A little winded writing but trying to give as much info as I can and thanks again for your help.

  • #6
    New to the CF scene
    Join Date
    Feb 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks for this answer

  • #7
    New to the CF scene
    Join Date
    Jun 2012
    Posts
    9
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Trying to include it in a simple modal box instead of a new page.

  • #8
    New to the CF scene
    Join Date
    Jun 2012
    Posts
    9
    Thanks
    1
    Thanked 0 Times in 0 Posts
    @LearningCoder

    Quote Originally Posted by LearningCoder View Post
    Yup I really can't see why you are trying to include a file and then echo a value within the include statement. If you want to use another file to echo a value, you can do this:
    PHP Code:
    include("page.php?aid=some_value"); 
    THEN, within your page.php script, you can do this:
    PHP Code:
    if(isset($_GET['aid']))
    {
         echo 
    $_GET['aid'];
    }
    else
    {
        echo 
    "$_GET variable not set.";

    OR, do this:
    PHP Code:
    $get = (isset($_GET['aid'])) ? $_GET['aid'] : "$_GET variable not set";

    echo 
    $get
    Does this help at all? Test it out and see what you think.

    Regards,

    LC.
    Thanks for the help but no it did not work.
    The previous way I had it was in a link
    Code:
    http://www.example.com.page.php?aid=<?php echo $id; ?>
    where $id; would pull the user id from the database and show certain information for that user on a new page ex: url output would have been http://example.com/page.php?aid=234 234 would be for user John D and show his information. Now I'm just trying to open it in a simple modal window by triggering the modal and within the modal body theres a php include of the url so the output would show the same information but I am having the issue of pulling the $id because it is already with <?php ?> and trying echoing the $id within the include only comes blank within the modal box body. A little winded writing but trying to give as much info as I can and thanks again for your help.

  • #9
    Regular Coder LearningCoder's Avatar
    Join Date
    Jan 2011
    Location
    The Pleiades
    Posts
    924
    Thanks
    76
    Thanked 29 Times in 29 Posts
    Sorry I've just read the question again. I think you may want this:
    PHP Code:
    <?php include 'page.php?aid={$id}'?>
    That passes the information to your page.php script.

    If you only want to echo it out and not go to a new page, why are you passing that variable through the URL of page.php?

    Maybe I'm completely missing the point, I'm not sure.

    Regards,

    LC.

  • #10
    New to the CF scene
    Join Date
    Jun 2012
    Posts
    9
    Thanks
    1
    Thanked 0 Times in 0 Posts
    thanks but thats not working either when the modal is triggered it is still blank and doesnt pull the data. Sorry for making it alittle confusing. the original file worked fine just didnt want to move away from the page when trying to view the data trying to make it where a modal is opened and the data populates into the model window.

  • #11
    Regular Coder
    Join Date
    May 2011
    Posts
    240
    Thanks
    1
    Thanked 56 Times in 55 Posts
    You can't use include this way. Check the example #3 of the manual for more details.
    You could just use the variable $id in the included script but I don't recommend it.
    PHP Code:
    <?php
    // page1.php
    $id "test";
    include 
    "page2.php";
    PHP Code:
    <?php
    // page2.php
    echo $id;
    A better solution would be a function or method call to do the job.

  • #12
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,352
    Thanks
    61
    Thanked 528 Times in 515 Posts
    Quote Originally Posted by LearningCoder View Post
    Sorry I've just read the question again. I think you may want this:
    PHP Code:
    <?php include 'page.php?aid={$id}'?>
    That passes the information to your page.php script.
    No it does not. If its a URL, yes, if its a local file then no it will not pass any url parameters. It will just include the local file as a file with no url parameters.

    Why?

    Think about it LC. The url parameters are processed by the WEB SERVER and passed to PHP.

    When including a local file, PHP accesses the file system directly - not a web server. With no web server involved in the process, how are the url parameters going to be processed? They won't.

    @eureka: You can't use another set of <?php ?> tags inside existing <?php ?> tags. It just doesn't work - you are already in php mode.
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!

  • Users who have thanked tangoforce for this post:

    LearningCoder (02-10-2013)

  • #13
    Regular Coder
    Join Date
    May 2011
    Posts
    240
    Thanks
    1
    Thanked 56 Times in 55 Posts
    Quote Originally Posted by tangoforce View Post
    No it does not. If its a URL, yes, if its a local file then no it will not pass any url parameters. It will just include the local file as a file with no url parameters.
    Actually, it will try to include the file without success because there is no file named 'page.php?aid=some_value' on the local filesystem.

  • #14
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,352
    Thanks
    61
    Thanked 528 Times in 515 Posts
    Quote Originally Posted by gvre View Post
    Actually, it will try to include the file without success because there is no file named 'page.php?aid=some_value' on the local filesystem.
    Good point! I must be loosing the plot..
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!


  •  

    Posting Permissions

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