Page 1 of 2
Passing variable value to iframe
Posted: Tue Oct 19, 2004 3:25 pm
by ljCharlie
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
Posted: Tue Oct 19, 2004 3:39 pm
by Weirdan
- 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">';
Posted: Wed Oct 20, 2004 9:30 am
by ljCharlie
Many thanks for the help but I still can not get it work. Below are my codes that are on the maingpage.php:
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();}
?>
The error occurs on this line
Code: Select all
echo '<iframe src="'.$scr.('?var='.$sectnID:'').'" id="thumbnail" width="535" height="100" frameborder="0" scrolling="auto" name="myInlineFrame"></iframe>';
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
Posted: Wed Oct 20, 2004 9:38 am
by feyd
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"
Posted: Wed Oct 20, 2004 10:07 am
by ljCharlie
The reason I did not use this:
Code: Select all
. ( isset($_GET['var']) ? '?var=' . $_GET['var'] : ''
is because I already have this:
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;
}
}
at the top of the page. Are you saying they are not the same thing?
ljCharlie
Posted: Wed Oct 20, 2004 10:17 am
by ljCharlie
feyd, I think I see your point. I got it working partially now. At least there is no error so far.
Thanks!
ljCharlie
Posted: Wed Oct 20, 2004 1:42 pm
by ljCharlie
Weirdan, your code:
Code: Select all
echo '<a href="index.php?var=' . $blah . '" target="_parent">';
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
Posted: Wed Oct 20, 2004 1:52 pm
by feyd
_parent is the window that created the frame.
Posted: Wed Oct 20, 2004 2:10 pm
by ljCharlie
Okay, here's my code:
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******************************************
?>
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
Posted: Wed Oct 20, 2004 2:14 pm
by feyd
does the image output inbetween table cells/rows? If so, that'll make the image appear "before" the table...
Posted: Wed Oct 20, 2004 2:26 pm
by 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>
Posted: Wed Oct 20, 2004 2:29 pm
by feyd
I don't see where you actually tell the larger image to show 'here' as upposed to 'there'
Posted: Wed Oct 20, 2004 2:34 pm
by ljCharlie
I didn't paste the code PHP code but the full image are suppose to be displayed be low this line:
Code: Select all
//****************************************Display the full picture below here************************************
ljCharlie
Posted: Wed Oct 20, 2004 2:56 pm
by ljCharlie
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>';
}
?>
Posted: Wed Oct 20, 2004 3:08 pm
by ljCharlie
I figured it out. It's working now.
ljCharlie