PHP hyperlinks in a iFrame passing to a iFrame in index.php

Ask about a PHP problem here.
Post Reply
chris122380
Posts: 9
Joined: Thu Jul 26, 2012 3:17 pm
Contact:

PHP hyperlinks in a iFrame passing to a iFrame in index.php

Post by chris122380 »

I am working on making a php site and am fairly new to php. The home page index.php has two iframes one on the left (name=pages) and one on the right (name=pdf). Above the iframe on the left are CSS buttons to open php files into the left iframe. One of the php files (Spec_list.php) opens with links generated from mysql into the left iframe. The links work when loading just the Spec_list.php but for some strange reason do not load when loading in the iframe. (both php files located in the same folder). I would then also like to get the links to open there pdf files into the iframe on the right hand side. I would like to be able to open diffident php files similar to spec_list.php in the left side who's links then open into the right iframe.

Index.php [syntax=php]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>Main Page</title>
<link href="css/Untitled_1.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" href="css/Untitled_1.css" type="text/css" media="screen, projection"/>
<!--[if lte IE 7]>
<link rel="stylesheet" type="text/css" href="css/ie.css" media="screen" />
<![endif]-->

<script type="text/javascript" src="js/jquery-1.3.1.min.js"></script>
<script type="text/javascript" language="javascript" src="js/jquery.dropdownPlain.js"></script>
</head>

<body>

<div id="body">
<div id="left">
<ul class="dropdown">
<li><a href="spec/Spec List.php" target="pages">Specification</a></li>
<li><a href="../aboutus.htm" target="pages">About Us</a></li>
<li><a href="../contact.htm" target="pages">Contact Us</a></li>
</ul>

<!-- Test Div <div id="pages" style='width: 400px; height:600px; background-color:gray; clear: both; overflow: auto; padding: auto 15px;'></div> -->
<iframe name="pages" style="width: 399px; height:775px; clear:both; overflow:auto; padding: auto 15px;" border="0" frameborder="0"></iframe>

</div>

<div id="right">

<iframe name="pdf" style="width: 617px; height:793px; clear:both; overflow:auto; " border="0" frameborder="0"></iframe>

</div>

<div id="bottom"> </div>

</div>

</body>

</html>
[/syntax]spec_list.php[syntax=php]<?php
// List Projects spec numbers with links to there spec numbers

include('conect.php');

//Query to pull data from Chris Anthony Business (Should be changed to userID variable to work with login and password system. May need new query or may need new relationships.
$query = mysql_query("SELECT `contacts`.`first_name`, `contacts`.`last_name`, `contacts`.`company`, `spec`.`spec`, `spec`.`discription` FROM `canthony`.`project_spec` AS `project_spec`, `canthony`.`project` AS `project`, `canthony`.`spec` AS `spec`, `canthony`.`contacts` AS `contacts` WHERE `project_spec`.`Project_ID` = `project`.`Project_ID` AND `project_spec`.`spec` = `spec`.`spec` AND `contacts`.`first_name` = 'Chris' AND `contacts`.`last_name` = 'Anthony'"); //query the database

//fetch the results and convert results into an array
WHILE ($rows = mysql_fetch_array($query)): //Fetch data from $query as long as there is data to fetch

$rows = preg_replace('/[\x00-\x1F\x80-\xFF]/', '', $rows); //Makes $rows variables print friendly characters

// assign fields from the query to Variables
$first_name = $rows['first_name'];
$last_name = $rows['last_name'];
$company = $rows['company'];
$spec = $rows['spec'];
$discription = $rows['discription'];

$spec = str_replace (" ", "", $spec); //removes spaces from $spec variable

echo '<a href="spec/',$spec,'.pdf">',$spec,'&nbsp;',$discription,'</a><br/>';
// "$spec&nbsp;$discription": $pdf="$spec"; break;

endwhile;

?>
[/syntax]

I have also tried by converting my variables to session variables and the spec_list.php links still will not work when loaded in the left iframe.
Local Server: XAMMP 1.8.0, Windows 7 64bit
Local PHP: 5.4.4
Local Apache: 2.4.2
Local MySQL: 14.14 Distrib 5.5.25a, for Win32 (x86)
PHP/HTML Editor: Komodo Edit, version 7.1.0
chris122380
Posts: 9
Joined: Thu Jul 26, 2012 3:17 pm
Contact:

Re: PHP hyperlinks in a iFrame passing to a iFrame in index.

Post by chris122380 »

I have figured out how to pass the page to the iframe. Had to move the echo and the endwhile to the body of the html. Like so, [syntax=php]<body>
<a href="spec/<?php echo $_SESSION['spec']; ?>.pdf" target="pdf"> <?php echo $_SESSION['spec'],'&nbsp;',$_SESSION['discription'], '<br />'; ?> </a>
<?php endwhile; ?>
</body>[/syntax]

Now I am trying to figure out how to clear the iframe when clicking on a link that doesn't use it.
Local Server: XAMMP 1.8.0, Windows 7 64bit
Local PHP: 5.4.4
Local Apache: 2.4.2
Local MySQL: 14.14 Distrib 5.5.25a, for Win32 (x86)
PHP/HTML Editor: Komodo Edit, version 7.1.0
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: PHP hyperlinks in a iFrame passing to a iFrame in index.

Post by jacek »

chris122380 wrote:Now I am trying to figure out how to clear the iframe when clicking on a link that doesn't use it.

That's not going to be possible :( Links can only affect an Iframe if their target is set to that frame. You will have to try some JavaScript to get it to work. You could also add a clear link which would be a lot easier

[syntax=xhtml]<a href="blank.html" target="pdf">Clear</a>[/syntax]
Image
chris122380
Posts: 9
Joined: Thu Jul 26, 2012 3:17 pm
Contact:

Re: PHP hyperlinks in a iFrame passing to a iFrame in index.

Post by chris122380 »

jacek wrote:
chris122380 wrote:Now I am trying to figure out how to clear the iframe when clicking on a link that doesn't use it.

That's not going to be possible :( Links can only affect an Iframe if their target is set to that frame. You will have to try some JavaScript to get it to work. You could also add a clear link which would be a lot easier

[syntax=xhtml]<a href="blank.html" target="pdf">Clear</a>[/syntax]


This only gives me another link to clear the iframe. Is there a way to get it to clear when clicking a link that opens a file in the left iframe or when clicking a link that isn't in it's iframe? I am ok using js if I know what code to use.
Local Server: XAMMP 1.8.0, Windows 7 64bit
Local PHP: 5.4.4
Local Apache: 2.4.2
Local MySQL: 14.14 Distrib 5.5.25a, for Win32 (x86)
PHP/HTML Editor: Komodo Edit, version 7.1.0
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: PHP hyperlinks in a iFrame passing to a iFrame in index.

Post by jacek »

chris122380 wrote:This only gives me another link to clear the iframe. Is there a way to get it to clear when clicking a link that opens a file in the left iframe or when clicking a link that isn't in it's iframe?

jacek wrote:That's not going to be possible :( Links can only affect an Iframe if their target is set to that frame.

;)

Go with the JavaScript method.
Image
Post Reply