Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-10-2013, 05:17 PM   PM User | #1
eureka
New to the CF scene

 
Join Date: Jun 2012
Posts: 9
Thanks: 1
Thanked 0 Times in 0 Posts
eureka is an unknown quantity at this point
'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!
eureka is offline   Reply With Quote
Old 02-10-2013, 06:09 PM   PM User | #2
frank727
New Coder

 
Join Date: Sep 2007
Posts: 19
Thanks: 3
Thanked 0 Times in 0 Posts
frank727 is an unknown quantity at this point
Why are you trying to that in an include statement?
frank727 is offline   Reply With Quote
Old 02-10-2013, 06:21 PM   PM User | #3
eureka
New to the CF scene

 
Join Date: Jun 2012
Posts: 9
Thanks: 1
Thanked 0 Times in 0 Posts
eureka is an unknown quantity at this point
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.
eureka is offline   Reply With Quote
Old 02-10-2013, 06:42 PM   PM User | #4
LearningCoder
Regular Coder

 
LearningCoder's Avatar
 
Join Date: Jan 2011
Location: The Pleiades
Posts: 849
Thanks: 67
Thanked 28 Times in 28 Posts
LearningCoder is an unknown quantity at this point
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.
LearningCoder is offline   Reply With Quote
Users who have thanked LearningCoder for this post:
eureka (02-10-2013)
Old 02-10-2013, 07:04 PM   PM User | #5
eureka
New to the CF scene

 
Join Date: Jun 2012
Posts: 9
Thanks: 1
Thanked 0 Times in 0 Posts
eureka is an unknown quantity at this point
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.
eureka is offline   Reply With Quote
Old 02-10-2013, 07:56 PM   PM User | #6
cloudit
New to the CF scene

 
Join Date: Feb 2013
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
cloudit is an unknown quantity at this point
Thanks for this answer
cloudit is offline   Reply With Quote
Old 02-10-2013, 08:14 PM   PM User | #7
eureka
New to the CF scene

 
Join Date: Jun 2012
Posts: 9
Thanks: 1
Thanked 0 Times in 0 Posts
eureka is an unknown quantity at this point
Trying to include it in a simple modal box instead of a new page.
eureka is offline   Reply With Quote
Old 02-10-2013, 08:17 PM   PM User | #8
eureka
New to the CF scene

 
Join Date: Jun 2012
Posts: 9
Thanks: 1
Thanked 0 Times in 0 Posts
eureka is an unknown quantity at this point
@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.
eureka is offline   Reply With Quote
Old 02-10-2013, 08:21 PM   PM User | #9
LearningCoder
Regular Coder

 
LearningCoder's Avatar
 
Join Date: Jan 2011
Location: The Pleiades
Posts: 849
Thanks: 67
Thanked 28 Times in 28 Posts
LearningCoder is an unknown quantity at this point
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.
LearningCoder is offline   Reply With Quote
Old 02-10-2013, 08:44 PM   PM User | #10
eureka
New to the CF scene

 
Join Date: Jun 2012
Posts: 9
Thanks: 1
Thanked 0 Times in 0 Posts
eureka is an unknown quantity at this point
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.
eureka is offline   Reply With Quote
Old 02-10-2013, 08:55 PM   PM User | #11
gvre
Regular Coder

 
Join Date: May 2011
Posts: 212
Thanks: 1
Thanked 50 Times in 49 Posts
gvre is an unknown quantity at this point
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.
gvre is offline   Reply With Quote
Old 02-10-2013, 09:46 PM   PM User | #12
tangoforce
Senior Coder

 
tangoforce's Avatar
 
Join Date: Feb 2011
Location: Your Monitor
Posts: 3,498
Thanks: 44
Thanked 439 Times in 428 Posts
tangoforce will become famous soon enoughtangoforce will become famous soon enough
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.
__________________
Please wrap your code in [php] tags. It is a sticky topic and it HELPS us to HELP YOU!
TIP: Coding styles and $end errors :::::::::: TIP: Warning: Cannot modify header information - headers already sent :::::::::: TIP: Quotes / Parse error: syntax error, unexpected T_..
PHP Code:
//Please don't use this for your form processing:
if (isset($_POST['submit']))
//Internet explorer has a bug and does not always send the submit value. 
Explanation: The IE if(isset($_POST['submit'])) bug explained.
tangoforce is offline   Reply With Quote
Users who have thanked tangoforce for this post:
LearningCoder (02-10-2013)
Old 02-10-2013, 09:56 PM   PM User | #13
gvre
Regular Coder

 
Join Date: May 2011
Posts: 212
Thanks: 1
Thanked 50 Times in 49 Posts
gvre is an unknown quantity at this point
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.
gvre is offline   Reply With Quote
Old 02-10-2013, 10:06 PM   PM User | #14
tangoforce
Senior Coder

 
tangoforce's Avatar
 
Join Date: Feb 2011
Location: Your Monitor
Posts: 3,498
Thanks: 44
Thanked 439 Times in 428 Posts
tangoforce will become famous soon enoughtangoforce will become famous soon enough
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..
__________________
Please wrap your code in [php] tags. It is a sticky topic and it HELPS us to HELP YOU!
TIP: Coding styles and $end errors :::::::::: TIP: Warning: Cannot modify header information - headers already sent :::::::::: TIP: Quotes / Parse error: syntax error, unexpected T_..
PHP Code:
//Please don't use this for your form processing:
if (isset($_POST['submit']))
//Internet explorer has a bug and does not always send the submit value. 
Explanation: The IE if(isset($_POST['submit'])) bug explained.
tangoforce is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:28 PM.


Advertisement
Log in to turn off these ads.