Hi everyone,

Ok, what I want to do is display a url that's stored in my database within an iframe when the specific record is selected.

The code I had to display the record correctly is:

<?php
$conn = mysql_connect(HOST,USER,PASS);
$db = mysql_select_db("***") or die( "Unable to select database");
if(isset($_GET["id"]))
{
$gethotel= mysql_query ("SELECT * FROM "***" WHERE id='$_GET[id]'") or die(mysql_error());
$count = mysql_num_rows($gethotel);
     if($count == 1)
     {
     $row = mysql_fetch_assoc($gethotel);
     {
     $hotel= $row['link_text'];
     $address = $row['address'];
     $telephone= $row['telephone'];
	 $url= $row['telephone'];
       echo "<strong> $hotel </strong><br /> $address <br /> Telephone: $telephone <br />";
     }
     }
 elseif($count==0)
{
 echo "There is no hotel with that name found!";
}
}
 else
{
 echo "There is no hotel found!";
}
?>

And then I was trying to pull the result from the "url" field in the database and display it using the following:

<?php
$conn = mysql_connect(HOST,USER,PASS);
$db = mysql_select_db("****") or die( "Unable to select database");
if(isset($_GET["id"]))
{
$gethotel= mysql_query ("SELECT * FROM "****" WHERE id='$_GET[id]'") or die(mysql_error());
$count = mysql_num_rows($gethotel);
     if($count == 1)
     {
     $row = mysql_fetch_assoc($gethotel);
     {
	 $url= $row['url'];
{
 echo  "<iframe src=$url style="background: #fff;" frameborder="0" height="450" scrolling="auto" width="100%"></iframe>";
}
?>

Although that doesn't work - does anyone know where I'm going wrong?

thanks :)

Hi everyone,

Ok, what I want to do is display a url that's stored in my database within an iframe when the specific record is selected.

The code I had to display the record correctly is:

<?php
$conn = mysql_connect(HOST,USER,PASS);
$db = mysql_select_db("***") or die( "Unable to select database");
if(isset($_GET["id"]))
{
$gethotel= mysql_query ("SELECT * FROM "***" WHERE id='$_GET[id]'") or die(mysql_error());
$count = mysql_num_rows($gethotel);
     if($count == 1)
     {
     $row = mysql_fetch_assoc($gethotel);
     {
     $hotel= $row['link_text'];
     $address = $row['address'];
     $telephone= $row['telephone'];
	 $url= $row['telephone'];
       echo "<strong> $hotel </strong><br /> $address <br /> Telephone: $telephone <br />";
     }
     }
 elseif($count==0)
{
 echo "There is no hotel with that name found!";
}
}
 else
{
 echo "There is no hotel found!";
}
?>

And then I was trying to pull the result from the "url" field in the database and display it using the following:

<?php
$conn = mysql_connect(HOST,USER,PASS);
$db = mysql_select_db("****") or die( "Unable to select database");
if(isset($_GET["id"]))
{
$gethotel= mysql_query ("SELECT * FROM "****" WHERE id='$_GET[id]'") or die(mysql_error());
$count = mysql_num_rows($gethotel);
     if($count == 1)
     {
     $row = mysql_fetch_assoc($gethotel);
     {
	 $url= $row['url'];
{
 echo  "<iframe src=$url style="background: #fff;" frameborder="0" height="450" scrolling="auto" width="100%"></iframe>";
}
?>

Although that doesn't work - does anyone know where I'm going wrong?

thanks :)

A problem that stands out is your echo on line 14. You have to escape all the quotes in your iframe tag and add some around your $url variable. Or you can put your iframe in HTML.

Replace

echo  "<iframe src=$url style="background: #fff;" frameborder="0" height="450" scrolling="auto" width="100%"></iframe>";

with

?>
<iframe src="$url" style="background: #fff;" frameborder="0" height="450" scrolling="auto" width="100%"></iframe>
<?php

If that isn't your problem, can you post the error you see or the at least the HTML that is returned.

Hi, Thanks for the reply.

I actually figured it out with a bit of help about 10 minutes ago.

I used the following:

<?php
$conn = mysql_connect(HOST,USER,PASS);
$db = mysql_select_db("***") or die( "Unable to select database");
if(isset($_GET["id"]))
{
$gethotel= mysql_query ("SELECT * FROM "****" WHERE id='$_GET[id]'") or die(mysql_error());
$count = mysql_num_rows($gethotel);
     if($count == 1)
     {
     $row = mysql_fetch_assoc($gethotel);
     {
     $hotel= $row['link_text'];
     $address = $row['address'];
     $telephone= $row['telephone'];
	 $url= $row['url'];
       echo "<strong> $hotel </strong><br /> $address <br /> Telephone: $telephone <br />";
     }
     }
 elseif($count==0)
{
 echo "There is no hotel with that name found!";
}
}
 else
{
 echo "There is no hotel found!";
}
?>

followed by

<?php

echo  "<iframe src=\"{$url}\" style=\"background: #fff;\" frameborder=\"0\" height=\"450\" scrolling=\"auto\" width=\"100%\"></iframe>";  

?>

to display the url inside the iframe.

It's kinda hard working it out when I'm pretty much self taught, so thanks for the pointers :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.