Jump to content


Photo

How to put IFRAME into php file


  • Please log in to reply
6 replies to this topic

#1 lilywong

lilywong
  • Members
  • PipPipPip
  • Advanced Member
  • 56 posts

Posted 09 March 2006 - 05:28 AM

I have a switch case like follow, and i want to put the iframe like (<iframe width=400 height=280 src ="default.php"></iframe>) inside the include, is there any way to do this ?
i do not want to limit the src link to default.pgp, i want it to goes with what i have selected from the switch case, is there any way to do this ?

<?php

switch(acGet("sec"))
{
case "ad_manage_user" : include_once("../admin/manage_user.php"); break;
case "ad_manage_folder" : include_once("../admin/manage_folder.php"); break;
case "ad_assign_folder" : include_once("../admin/assign_folder.php"); break;
}

?>

thanks



#2 fusionpixel

fusionpixel
  • Members
  • PipPipPip
  • Advanced Member
  • 64 posts

Posted 09 March 2006 - 06:17 AM

why dont you just dump the variable into the IFrame instead?

something like this.....


#By no means this code is supposed to work, its just to give you an idea.
function writeIFrame($theFrame){
echo ("<iframe width=400 height=280 src ='$theFrame'></iframe>");
};

writeIFrame($acGet);

Did you know there is a manual for PHP? [a href="http://" target="_blank"]http://www.php.net[/a]
Did you know there is a manual for mySQL? [a href="http://" target="_blank"]http://www.mysql.org[/a]

#3 lilywong

lilywong
  • Members
  • PipPipPip
  • Advanced Member
  • 56 posts

Posted 09 March 2006 - 07:03 AM

sorry i am newbie, can't understand the code, do you mind to give details explanations and example in regards to my problem? thanks

#4 fusionpixel

fusionpixel
  • Members
  • PipPipPip
  • Advanced Member
  • 64 posts

Posted 09 March 2006 - 08:09 AM

Ok, maybe I missunderstood what you are trying to acomplish, but for what I saw on your code you are trying to add content to an IFrame depending on the variable you are receiving, and the way you are handling this is through a CASE statement.

Well, what I was suggesting was to write down a function that receives the path of the file you want to load to the IFrame. that will save you extra steps.

Here is an example that I slapped together:

Enter the page you want to load into the Iframe
#this is just a sample form to show you how to pass the file path variable
<form method="get" action=''>
<input type='text' name='loadToIFrame'></input>
<input type='submit' value='submit'/>
</form>
<br />
<?
#simple if statement to check if we have declared the variable, if we havent declared a variable then a default page gets loaded to avoid ugly 404 errors.
if (!$loadToIFrame){
$loadToIFrame = 'www.google.com';
}else{
$loadToIFrame = $_GET['loadToIFrame'];
}
echo 'iframe to load= '.$loadToIFrame.'<br /><br />';
?>

<--! This is where we actually load the frame -->
<iframe width=600 height=280 src='<? echo 'http://'.$loadToIFrame; ?>'></iframe>


click here to see it in action:
[a href=\"http://www.helmutgranda.com/php/phpiframe/\" target=\"_blank\"]http://www.helmutgranda.com/php/phpiframe/[/a]


I hope that helps!
Did you know there is a manual for PHP? [a href="http://" target="_blank"]http://www.php.net[/a]
Did you know there is a manual for mySQL? [a href="http://" target="_blank"]http://www.mysql.org[/a]

#5 lilywong

lilywong
  • Members
  • PipPipPip
  • Advanced Member
  • 56 posts

Posted 09 March 2006 - 09:40 AM

hmm..... i do not want to key in data into text field.

in this case, there are three buttons, (Manage User, Manage Folder, Assign Folder),
for eg, when i click Manage User button, the main page will include the (case "ad_manage_user" : include_once("../admin/manage_user.php") automatically. any idea ?

thank you so much !!



#6 fusionpixel

fusionpixel
  • Members
  • PipPipPip
  • Advanced Member
  • 64 posts

Posted 09 March 2006 - 04:57 PM

Well, you dont HAVE TO use the text field, it was just a sample of how you could get things to work. I created a new small script that does similar to what you are asking (at least I think so) :)

<script language='javascript'>
function getNewPage(thePage){
open ('index.php?loadToIFrame='+thePage, '_self');
}
</script>

<input type='button' onclick="getNewPage('www.google.com'); return false" value='google'>&nbsp;<input type='button' onclick="getNewPage('www.amazon.com'); return false" value='amazon'>&nbsp;<input onclick="getNewPage('www.helmutgranda.com'); return false" type='button' value='helmut'>
<br />
<?
#simple if statement to check if we have declared the variable, if we havent declared a variable then a default page gets loaded to avoid ugly 404 errors.
$loadToIFrame = $_GET['loadToIFrame'];

if (!$loadToIFrame){
$loadToIFrame = 'www.google.com';
}else{
$loadToIFrame = $_GET['loadToIFrame'];
}
echo 'iframe to load= '.$loadToIFrame.'<br /><br />';
?>

<!-- This is where we actually load the frame -->
<iframe width=600 height=280 src='<? echo 'http://'.$loadToIFrame; ?>' name='holder'></iframe>

Working Sample:

[a href=\"http://www.helmutgranda.com/php/phpiframe2/\" target=\"_blank\"]http://www.helmutgranda.com/php/phpiframe2/[/a]
Did you know there is a manual for PHP? [a href="http://" target="_blank"]http://www.php.net[/a]
Did you know there is a manual for mySQL? [a href="http://" target="_blank"]http://www.mysql.org[/a]

#7 lilywong

lilywong
  • Members
  • PipPipPip
  • Advanced Member
  • 56 posts

Posted 10 March 2006 - 01:45 PM

hi yah, sorry for trobling you so much, what i mean is, i want to include the a file into the main page (main.php), not to change the whole page which i click the button.

For example, the main page maybe like below:

buttonA buttonB buttonC buttonD ---> Header(put in main.php)

=============================

contents area are here, and the iframe also
put here

-------> contents area, show include file
for eg, if buttonA is clicked, should
include file like
include_once("../admin/A.php")



=============================
copyright @ 123 company, 2003 -------------> Footer (put in main.php)


buttonA link to A.php, buttonB link to B.php,
buttonC link to C.php, buttonD link to D.php.
so, when i click buttonA, the contens area should only display A.php,
which only have include_once("../admin/A.php"), this because the A.php need to take variable from the main.php as well, so must use include in this way, do you get what i mean ?

Thank you so much







0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users