【问题标题】:Display data on top of image PHP在图像 PHP 上显示数据
【发布时间】:2015-05-25 03:33:36
【问题描述】:

从图片中可以看出:http://prntscr.com/78wcje

数据未显示在图像顶部。

完整代码:http://pastebin.com/Z1ecden0

<h1>Pernix RsPs<br />
  Official ItemDB!</h1>
<br />
<form action="search.php" method="POST">
<input type="text" name="search" /><br /><br />
<input type="Submit" value="Search ItemDB" />
</form>
 <table border="0" width="400">
  <img src="top.png"></table>
  <table border="1" width="400">
 <?php
    $search = $_POST["search"];
        MySQL_connect("localhost", "host", "pass");
        MySQL_select_db("dbname");
        $result = mysql_query("SELECT * FROM items WHERE name LIKE '%" . mysql_real_escape_string($search) . "%'  ORDER by name") or trigger_error(mysql_error().$sql);

while($row = mysql_fetch_array($result))
  {
  ?>

<?

    echo '<tr>';
    echo '<img src="post.png">';
    echo '<td>' . $row['img'] . '</td>';
    echo '<td>' . $row['name'] . '</td>';
    echo '<td>' . $row['price'] . '</td>';

    echo '</tr>';
        }
    }
?>  

</table>
</center>

【问题讨论】:

  • 你想让top.png图片作为表格的背景?
  • 是的,所以拉取数据时是这样的,prntscr.com/78wgpn

标签: html mysql css


【解决方案1】:

只需在桌子周围放一个 div,名称为 theme,如下所示

<div class="theme">
<table border="1" width="400">
 <?php
    $search = $_POST["search"];
        MySQL_connect("localhost", "pernixr2_ge", "pass");
        MySQL_select_db("pernixr2_ge");
        $result = mysql_query("SELECT * FROM items WHERE name LIKE '%" . mysql_real_escape_string($search) . "%'  ORDER by name") or trigger_error(mysql_error().$sql);

while($row = mysql_fetch_array($result))
  {
  ?>

<?

    echo '<tr>';
    echo '<img src="post.png">';
    echo '<td>' . $row['img'] . '</td>';
    echo '<td>' . $row['name'] . '</td>';
    echo '<td>' . $row['price'] . '</td>';

    echo '</tr>';
        }
    }
?>  

</table>
</div>

并在您的 .css 文件中添加此代码

.theme-table, .theme {
    height: 100%;
    width: 100%;  
}

.theme-table {
    border:1px solid black;
    table-layout: fixed;

}

.theme {
    background:url(http://www.psdgraphics.com/wp-content/uploads/2012/04/light-wooden-background.jpg);
    background-repeat:no-repeat;
}

注意:

top.png或任何你想做的图片替换图片的url

更新:

由于 mysql 已被贬值,我已经使用 mysqli 给出了代码,它在内部具有样式

<?php
$Connection = new mysqli("localhost", "root", "", "mysqli");
if ($Connection->connect_errno) 
{
    echo "Connection Failed".$Connection->connect_error;
    exit();
}
$query = "SELECT * from users";
if ($result = $Connection->query($query)) {
?>
<div class="theme">
<style type="text/css">
.theme {
    background:url(http://www.psdgraphics.com/wp-content/uploads/2012/04/light-wooden-background.jpg);
    background-repeat:no-repeat;
}

</style>
<table style="width:45%" border="1">
  <tr>
    <td>Jill</td>
    <td>Smith</td> 
    <td>50</td>
  </tr>
  <?php
    while ($row = $result->fetch_assoc()) 
    {
        echo "
                <tr>
                    <td>".$row["id"]."</td> 
                    <td>".$row["username"]."</td>
                    <td>".$row["username"]."</td>
                  </tr>
        ";
    }
    $result->free();
}
?>
</table>
</div>
<?php
$Connection->close();
?>

这里是Image

【讨论】:

  • 对不起.. 删除 height: 100%; width: 100%; 或者只是在 css 中删除它
  • 你从来没有放 100% 的宽度/高度,我从你给 em 的 CSS 中删除了“高度:747 像素;宽度:76 像素;”,现在我有了这个:prntscr.com/78wn64 这仍然是错误的,因为它应该在每个结果下绘制该图像:prntscr.com/78wnjl
  • 好的,等待 2 分钟,它必须是 css 中的小修复,我会在 2 分钟内更新它:)
  • 在我开始之前只是一个小小的说明。你是否从你的代码中删除了&lt;center&gt; 标签。 ?因为它每次都使桌子居中
  • 我还有中心标签
猜你喜欢
  • 2015-03-25
  • 2014-05-29
  • 2020-06-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-01-30
  • 2021-03-01
相关资源
最近更新 更多