0

In my index.php file I have this

$answer = $a + $b;
echo '<iframe src="ianswer.php".....etc. etc.

ianswer.php contains only the following line

echo $answer;

But the ianswer.php doesn't know what $answer is.

If I change that line to

echo "RUBBISH";

The word RUBBISH appears in the iframe.

How do I get it to display the answer?

I searched the web and played around with GLOBAL, $GLOBALS and $_SESSION but none of the examples I found work.

5
Contributors
8
Replies
9
Views
6 Years
Discussion Span
Last Post by joedy
0

Try:
echo '<iframe>';
include 'ianswer.php';
echo 'etc. </iframe>';

Edited by cgull: n/a

0

@cgull
That was smart and simple... I'll also try using it in the future. Any idea how to get info from an Iframe page into our PHP parent page?

0

Hi,
I never used iframe so I'm not sure, but I would say you would need to call the php parent page and send it parameters.

Something like:

<a href="parent.php?parameter1=something&ampparameter2=something">Call Parent</a>

I need more details of what you are trying to do, in order to help.

0

The idea of the IFRAME is to include web page inside other page with different configurations and functions, NOT TO WORK TOGETHER, only to display the iframepage content in the main page.
If your idea is to display the results from your main page you should not use Iframe.

How ever, if you want on some reason to be this way you may use a php GET function..

At your iframe code add src

<iframe src="page.php?answer=".$answer."">

And inside your page.php add

$answer=$_GET["answer"];

:)

Edited by sv3tli0: n/a

0

Do you really need to use iframe?
Why not just use an include?
I'm assuming that all these files are on the same domain.
The only 'advantage' I can see with this is the ease of changing content via js as it doesn't need ajax.

0

Hi

Thanks for all your help

sv3tli0 has come closet to solving my problem, but not quite.

If I change the code to $answer = '6';

The 6 gets passed to the file.

But when $answer = $a + $b nothing gets passed to the file.

When I view the source of the main page, with $answer = '6';

I get this <iframe src="page.php?answer=6"

But using $answer = $a + $b I get this

<iframe src="page.php?answer="

The value of $answer is not getting echoed in the html.

I tried adding echo $answer; on the line before the iframe code, and the value for answer appears there whether it is $a + $b or just '6'

0
$answer = $a + $b;

this is a math formula and it may only counts .
So if you have inputed $a and $b it will calculate to some number .
You can set

if(!$a&&!$b)$answer=0;

P.S. be carefull not to miss some element. You may copy paste your code here to make better advice.

Edited by sv3tli0: n/a

0

Hi

Please ignore my previous post, sv3tli0's post was spot on.

I did not write the original code, but whoever did, created the address of the iframe page with a number of variables, i.e.

$PartOne = 'http://';
$PartTwo = 'www.';
$PartFive = '.com';

etc. etc.

For some reason he also had

$dq = chr(34);

And used $dq whenever he needed double quotes in the address.

I took out $dg and replaced it with real double quotes and it works perfectly now.

So a big thanks you to all those who helped.

For anyone interested, the reason he wanted it done this way is he gets paid $5 per month to have a banner on his site. But he can't have any other banners on the page unless they are in iframes.

He didn't want the obvious answer of having a separate html file to display each banner, then just load the relevant html file into the iframe. Instead he wanted to pass a variable to a php file and it would then know which banner to display.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.