[SOLVED] Passing variable value to iframe
Moderator: General Moderators
Passing variable value to iframe
How do I pass a variable value from a hyper link to a .php file that is in the iframe tag? The second question is, how do I send a value in the iframe .php file back to the page that contains the iframe?
Any help is appreciated!
ljCharlie
Any help is appreciated!
ljCharlie
- in your containing page add any variable you need in src attribute of iframe tag:
Code: Select all
$src = 'some_file.php'; echo '<iframe src="' . $src . ( isset($_GET['var']) ? '?var=' . $_GET['var'] : '' ) . '">'; - use the hyperlink with _parent target. Assuming your containing page is called index.php:
Code: Select all
echo '<a href="index.php?var=' . $blah . '" target="_parent">';
Many thanks for the help but I still can not get it work. Below are my codes that are on the maingpage.php:
The error occurs on this line What I'm trying to do here is passing the variable $sectnID to the myIframePage.php page that is in the iframe.
Any help is grateful!
ljCharlie
Code: Select all
<?php require_once('Connections/alumniConnection.php'); ?>
<?PHP
if(!isset($HTTP_GET_VARS["sectionID"])){
$sectnID = $HTTP_GET_VARS["sectionID"];
if ($sectnID != ""){
setcookie("whichSection", $sectnID, time()+3600);
}
}
else{
$dfrntSectionID = $HTTP_GET_VARS["sectionID"];
$sectnID = $HTTP_COOKIE_VARS["whichSection"];
if ($dfrntSectionID != $sectnID){
$sectnID = $dfrntSectionID;
}
}
//*************************************************************************************
$self = $HTTP_SERVER_VARS['PHP_SELF'];
$pixID = $HTTP_GET_VARS["imageID"];
$hdnPixID = $HTTP_POST_VARS["hdPixID"];
$btnClicked = $HTTP_POST_VARS["btnClick"];
$numPicsID = array();
//*********************Connect to database and query**************
mysql_select_db($database_alumniConnection, $alumniConnection);
if ($sectnID != ""){
$query_rsSection = "SELECT * FROM photoGallery WHERE sectionID = ".$sectnID;
$rsSection = mysql_query($query_rsSection, $alumniConnection) or die(mysql_error());
$totalRows_rsSection = mysql_num_rows($rsSection);
$numOfPics = array($totalRows_rsSection);
}
//******************in the body tag****************************
if ($sectnID !=""){
$numOfCells=1;
}
if ($totalRows_rsSection >0){
if ($numOfCells ==1){
$src = 'galleryThumbNail.php';
echo '<iframe src="'.$scr.('?var='.$sectnID:'').'" id="thumbnail" width="535" height="100" frameborder="0" scrolling="auto" name="myInlineFrame"></iframe>';
}
}
else{ message();}
?>Code: Select all
echo '<iframe src="'.$scr.('?var='.$sectnID:'').'" id="thumbnail" width="535" height="100" frameborder="0" scrolling="auto" name="myInlineFrame"></iframe>';Any help is grateful!
ljCharlie
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
you didn't copy his example correctly. read this page: http://www.php.net/manual/en/language.o ... arison.php look for the bit on the "ternary"
The reason I did not use this: is because I already have this: at the top of the page. Are you saying they are not the same thing?
ljCharlie
Code: Select all
. ( isset($_GET['var']) ? '?var=' . $_GET['var'] : ''Code: Select all
if(!isset($HTTP_GET_VARS["sectionID"])){
$sectnID = $HTTP_GET_VARS["sectionID"];
if ($sectnID != ""){
setcookie("whichSection", $sectnID, time()+3600);
}
}
else{
$dfrntSectionID = $HTTP_GET_VARS["sectionID"];
$sectnID = $HTTP_COOKIE_VARS["whichSection"];
if ($dfrntSectionID != $sectnID){
$sectnID = $dfrntSectionID;
}
}ljCharlie
Weirdan, your code: is working except that I want to targe a specific row in the parent page. Is this possible? Here's what I'm trying to do. I am trying to display the thumbnails inside a iframe on the left side vertically, once the user click on the thumbnail image, pass the ID to a variable. This ID variable will be used to query the database to display the full picture on a table that is on the right side or main area. Right now the full picture is being displayed right below the iframe which is on the left side and the right side or main area contains nothing. I wonder if _parent means return back to where ever iframe was called.
Any help is grateful!
ljCharlie
Code: Select all
echo '<a href="index.php?var=' . $blah . '" target="_parent">';Any help is grateful!
ljCharlie
Okay, here's my code:
Now, the problem is when the full picture is display, it displays above these
<!-- InstanceEndEditable --></td>
<td rowspan="2"> </td>
<td height="219" valign="top" bgcolor="#FFFFFF">
lines of code instead of below it like the way I have in my code.
ljCharlie
Code: Select all
<?php <?php
//***************************************This section displays the submenu of each section*****************************
if ($totalRows_rsSection >0){
$src = 'galleryThumbNail.php';
//echo "<p></p><p></p>";
echo '<iframe src="'.$src.('?var='.$sectnID).'" id="thumbnail" width="209" frameborder="0" name="myInlineFrame"></iframe>';
}
else{
?>
<!-- InstanceEndEditable --></td>
<td rowspan="2"> </td>
<td height="219" valign="top" bgcolor="#FFFFFF">
<!-- InstanceBeginEditable name="Body" --><span class="headline01">PHOTO GALLERY</span><p></p>
<?PHP
message();
}
//****************************************Display the full picture below here******************************************
?><!-- InstanceEndEditable --></td>
<td rowspan="2"> </td>
<td height="219" valign="top" bgcolor="#FFFFFF">
lines of code instead of below it like the way I have in my code.
ljCharlie
Here's the table.
Code: Select all
<table width="755" border="0" cellpadding="0" cellspacing="0" bordercolor="#FFFFFF">
<tr>
<td> <table border="0" cellspacing="0" cellpadding="0" width="755">
<tr>
<td><img src="images/spacer.gif" width="210" height="4"></td>
<td><img src="images/spacer.gif" width="30" height="4"></td>
<td><img src="images/spacer.gif" width="535" height="4"></td>
</tr>
<tr bgcolor="#FFFFFF">
<td height="252" rowspan="2" valign="top"><p><img src="images/simg.gif" width="1" height="1" name="lftSideMenu"></p>
<!-- InstanceBeginEditable name="sideMenu" -->
<?php
//***************************************This section displays the thumbnails*****************************
if ($totalRows_rsSection >0){
$src = 'galleryThumbNail.php';
//echo "<p></p><p></p>";
echo '<iframe src="'.$src.('?var='.$sectnID).'" id="thumbnail" width="209" frameborder="0" name="myInlineFrame"></iframe>';
}
else{
?>
<!-- InstanceEndEditable --></td>
<td rowspan="2"> </td>
<td height="219" valign="top" bgcolor="#FFFFFF">
<!-- InstanceBeginEditable name="Body" --><span class="headline01">PHOTO GALLERY</span><p></p>
<?PHP
message();
}
echo "got here";
//****************************************Display the full picture below here************************************
function message(){
}
?><!-- InstanceEndEditable --></td>
</tr>
</table>
Last edited by ljCharlie on Wed Oct 20, 2004 2:37 pm, edited 1 time in total.
I didn't paste the code PHP code but the full image are suppose to be displayed be low this line:
ljCharlie
Code: Select all
//****************************************Display the full picture below here************************************And here's the table that list the thumbnails on the left side veritcaly in the iframe:
Code: Select all
<?php
//*******************This section display the thumbnail of the pictures****************************************
if ($totalRows_rsSection >0){
echo '<table width="140" border="0" cellpadding="0" cellspacing="0">';
while($row_rsSection = mysql_fetch_assoc($rsSection)){
$fileName = $row_rsSection["fileName"];
$location = $row_rsSection["path"];
$picID = $row_rsSection["imgID"];
$sectID = $row_rsSection["sectionID"];
echo '<tr>';
echo "<td>";
echo '
<table cellspacing=0 cellpadding=0 border=0 align="center" width=136>
<tr>
<td background="images/frame/border_top_left.gif" ><img src="images/frame/border_top_left.gif" width=18 height=18 border=0 alt=""/></td>
<td background="images/frame/border_top_middle.gif" ><img src="images/frame/border_top_middle.gif" width=104 height=18 border=0 alt=""/></td>
<td background="images/frame/border_top_right.gif" ><img src="images/frame/border_top_right.gif" width=18 height=18 border=0 alt=""/></td>
</tr>
<tr>
<td background="images/frame/border_left.gif" ><img src="images/frame/border_left.gif" width=18 height=74 border=0 alt=""/></td>';
echo "<td align='center' valign='middle'><a href=photoGallery.php?imageID=$picID§ionID=$sectID target='_parent' class='submenu'><img src='$location/$fileName' width='100'/></a></td>";
echo '<td background="images/frame/border_right.gif" ><img src="images/frame/border_right.gif" width=18 height=74 border=0 alt=""/></td>
</tr>
<tr>
<td background="images/frame/border_bottom_left.gif" ><img src="images/frame/border_bottom_left.gif" width=18 height=18 border=0 alt=""/></td>
<td background="images/frame/border_bottom_middle.gif" ><img src="images/frame/border_bottom_middle.gif" width=104 height=18 border=0 alt=""/></td>
<td background="images/frame/border_bottom_right.gif" ><img src="images/frame/border_bottom_right.gif" width=18 height=18 border=0 alt=""/></td>
</tr>
</table>';
echo "</td>";
echo "</tr>";
}
echo '</table>';
}
?>