iframe在PHP中不起作用?

时间:2013-02-25 21:07:00

标签: php html iframe

我有一个php文件,它将从mysql数据库中动态显示图像/产品列表!这个位工作得很好。

但我尝试使用iframe中的命令,因此我可以使用iframe创建幻灯片效果!

但是当我把iframe放在命令周围时它出于某种原因不起作用!它将在我的000web托管服务器上打开404页面!!

这是我的代码:

<?php
include "config/connect_to_mysql.php";
$sql = mysql_query("SELECT * FROM products ORDER BY date_added DESC LIMIT 10");
$i = 0;
// Establish the output variable
$dyn_table = '<table border="0" cellpadding="6">';
while($row = mysql_fetch_array($sql)){

    $id = $row["id"];

    if ($i % 5 == 0) { // if $i is divisible by our target number (in this case "5")
        $dyn_table .= '<tr><td><div style="position:relative" class="shadow tr" id="products_holder"><div style="position:absolute;left:-10px;top:-12px;">
    <img src="images/best.png" width="97" height="94" />
  </div><a href="product.php?id=' . $id . '"><img style=" margin:5px; border:#ccc 1px solid" src="inventory_images/' . $id . '.jpg" width="150" height="160"/></a></div></td>';
    } else {
        $dyn_table .= '<td><div style="position:relative" class="shadow tr" id="products_holder"><div style="position:absolute;left:-10px;top:-12px;">
    <img src="images/best.png" width="97" height="94" />
  </div><a href="product.php?id=' . $id . '"><img style=" margin:5px; border:#ccc 1px solid" src="inventory_images/' . $id . '.jpg" width="150" height="160"/></a></div></div></td>';
    }
    $i++;
}
$dyn_table .= '</tr></table>';
?>
<!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 http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="css/main.css">
    <link rel="stylesheet" href="style.css" type="text/css" media="screen" />
    <script src="scripts/modernizr-2.6.1.min.js"></script>
<title>site.com</title>
<style type="text/css">
</style>
</head>

<body>
<div align="center" id="wrapper">
  <?php include_once("temps/header.php"); ?>
  <div id="content">
    <div id="apDiv1">
    <h2>Top pros</h2></div>
  <table width="100%" border="0" cellspacing="0" cellpadding="17">
  <tr>
    <td width="2%" height="20">&nbsp;</td>
    <td width="98%" height="20"><p><?php echo $dyn_table; ?></p>

  </tr>
</table>
<table align="center" style=" table-layout:fixed; background-image:url(images/secondSection.png);" height="82" width="100%" border="0" cellspacing="10" cellpadding="10">
  <tr>
    <td width="2%" height="31">&nbsp;</td>
    <td style="vertical-align:top" align="center" width="28%"><div id="apDiv555" class="top_btns">&nbsp;&nbsp;&nbsp;&nbsp;
        <h6 class="shadow">&nbsp;More Products</h6>
    </div></td>
    <td style="vertical-align:top" align="center" width="70%"><div id="apDiv55" class="top_btns">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <h6><span class="shadow"><a href="#">&nbsp;&nbsp;&nbsp;Search By Clothing</a> &nbsp;|&nbsp;&nbsp;<a href="#">Search By Retailers</a></span></h6>
    </div></td>
    </tr>
</table>
<table style="background-image: url(images/tbl_bg.png); background-repeat: repeat-x;" height="350px" width="100%" border="0" cellspacing="12" cellpadding="0">
  <tr>
    <td width="3%"></td>
    <td width="97%"><iframe src="<?php echo $dyn_table; ?>" height="250" width="100%" ></iframe></td>
    </tr>
</table>
</table>
<table height="100" width="100%" border="0" cellspacing="17" cellpadding="17">
  <tr>
    <td>&nbsp;</td>
    </tr>
</table>

</div>

</div>
<?php include_once ("temps/footer.php"); ?>
</body>
</html>

任何帮助都会受到欢迎,因为我几乎完成了这个项目。

的Th

2 个答案:

答案 0 :(得分:1)

只是松开iFrame并回显你已经拥有的桌子里的$ dyn_table?

答案 1 :(得分:0)

您不知道iframe的含义,可能是:

    <!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 http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <link rel="stylesheet" type="text/css" href="css/main.css">
        <link rel="stylesheet" href="style.css" type="text/css" media="screen" />
        <script src="scripts/modernizr-2.6.1.min.js"></script>
    <title>site.com</title>
    <style type="text/css">
    </style>
    </head>

    <body>
    <div align="center" id="wrapper">
      <?php include_once("temps/header.php"); ?>
      <div id="content">
        <div id="apDiv1">
        <h2>Top pros</h2></div>
      <table width="100%" border="0" cellspacing="0" cellpadding="17">
      <tr>
        <td width="2%" height="20">&nbsp;</td>
        <td width="98%" height="20"><p><?php echo $dyn_table; ?></p>

      </tr>
    </table>
    <table align="center" style=" table-layout:fixed; background-image:url(images/secondSection.png);" height="82" width="100%" border="0" cellspacing="10" cellpadding="10">
      <tr>
        <td width="2%" height="31">&nbsp;</td>
        <td style="vertical-align:top" align="center" width="28%"><div id="apDiv555" class="top_btns">&nbsp;&nbsp;&nbsp;&nbsp;
            <h6 class="shadow">&nbsp;More Products</h6>
        </div></td>
        <td style="vertical-align:top" align="center" width="70%"><div id="apDiv55" class="top_btns">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            <h6><span class="shadow"><a href="#">&nbsp;&nbsp;&nbsp;Search By Clothing</a> &nbsp;|&nbsp;&nbsp;<a href="#">Search By Retailers</a></span></h6>
        </div></td>
        </tr>
    </table>
    <table style="background-image: url(images/tbl_bg.png); background-repeat: repeat-x;" height="350px" width="100%" border="0" cellspacing="12" cellpadding="0">
      <tr>
        <td width="3%"></td>
        <td width="97%"><iframe src="my_iframe.php" height="250" width="100%" ></iframe></td>
        </tr>
    </table>
    </table>
    <table height="100" width="100%" border="0" cellspacing="17" cellpadding="17">
      <tr>
        <td>&nbsp;</td>
        </tr>
    </table>

    </div>

    </div>
    <?php include_once ("temps/footer.php"); ?>
    </body>
    </html>

    // Context on the my_iframe.php

    <?php
    include "config/connect_to_mysql.php";
    $sql = mysql_query("SELECT * FROM products ORDER BY date_added DESC LIMIT 10");
    $i = 0;
    // Establish the output variable
    $dyn_table = '<table border="0" cellpadding="6">';
    while($row = mysql_fetch_array($sql)){

        $id = $row["id"];

        if ($i % 5 == 0) { // if $i is divisible by our target number (in this case "5")
            $dyn_table .= '<tr><td><div style="position:relative" class="shadow tr" id="products_holder"><div style="position:absolute;left:-10px;top:-12px;">
        <img src="images/best.png" width="97" height="94" />
      </div><a href="product.php?id=' . $id . '"><img style=" margin:5px; border:#ccc 1px solid" src="inventory_images/' . $id . '.jpg" width="150" height="160"/></a></div></td>';
        } else {
            $dyn_table .= '<td><div style="position:relative" class="shadow tr" id="products_holder"><div style="position:absolute;left:-10px;top:-12px;">
        <img src="images/best.png" width="97" height="94" />
      </div><a href="product.php?id=' . $id . '" target="_blank" onClick="window.open(this.href, this.target, 'width=300,height=400'); return false;"><img style=" margin:5px; border:#ccc 1px solid" src="inventory_images/' . $id . '.jpg" width="150" height="160"/></a></div></div></td>';
        }
        $i++;
    }
    $dyn_table .= '</tr></table>';
    echo $dyn_table;
    ?>

一个iframe它是一个完全不同的页面,所以你应该使用2个页面....就像一个建议,一个用于html,一个用于iframe ......我希望它有所帮助。

PS:我改变了a href;)

Saludos;)