0

我有一个 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>

任何帮助将不胜感激,因为我几乎完成了这个项目。

4

2 回答 2

1

只需松开 iFrame 并在您已有的表中回显 $dyn_table ?

于 2013-02-25T21:12:11.673 回答
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 ;)

萨卢多斯 ;)

于 2013-02-25T21:20:16.230 回答