[SOLVED] Passing variable value to iframe

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

ljCharlie
Forum Contributor
Posts: 289
Joined: Wed May 19, 2004 8:23 am

Passing variable value to iframe

Post 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
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

  1. 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'] : '' ) . '">';
  2. 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">';
ljCharlie
Forum Contributor
Posts: 289
Joined: Wed May 19, 2004 8:23 am

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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"
ljCharlie
Forum Contributor
Posts: 289
Joined: Wed May 19, 2004 8:23 am

Post 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
ljCharlie
Forum Contributor
Posts: 289
Joined: Wed May 19, 2004 8:23 am

Post 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
ljCharlie
Forum Contributor
Posts: 289
Joined: Wed May 19, 2004 8:23 am

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

_parent is the window that created the frame.
ljCharlie
Forum Contributor
Posts: 289
Joined: Wed May 19, 2004 8:23 am

Post 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">&nbsp;</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">&nbsp;</td>
<td height="219" valign="top" bgcolor="#FFFFFF">

lines of code instead of below it like the way I have in my code.

ljCharlie
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

does the image output inbetween table cells/rows? If so, that'll make the image appear "before" the table...
ljCharlie
Forum Contributor
Posts: 289
Joined: Wed May 19, 2004 8:23 am

Post 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">&nbsp;</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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

I don't see where you actually tell the larger image to show 'here' as upposed to 'there'
ljCharlie
Forum Contributor
Posts: 289
Joined: Wed May 19, 2004 8:23 am

Post 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
ljCharlie
Forum Contributor
Posts: 289
Joined: Wed May 19, 2004 8:23 am

Post 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&sectionID=$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>';
        }
?>
ljCharlie
Forum Contributor
Posts: 289
Joined: Wed May 19, 2004 8:23 am

Post by ljCharlie »

I figured it out. It's working now.

ljCharlie
Post Reply