【发布时间】:2011-09-10 22:27:19
【问题描述】:
我有一个结果页面,我希望页面顶部有一个显示返回多少结果的位置。我该怎么做?
我的代码是
<?php
if(strlen(trim($_POST['search'])) > 0) {
$search = "%" . $_POST["search"] . "%";
$searchterm = "%" . $_POST["searchterm"] . "%";
mysql_connect ("3", "", "");
mysql_select_db ("");
if (!empty($_POST["search_string"]))
{
}
$query = "SELECT name,location,msg FROM contact WHERE name LIKE '%$search%' AND
location LIKE '%$searchterm%'";
$result = mysql_query ($query);
if ($result) {
while ($row = mysql_fetch_array ($result)) { ?>
<center>
<table height="20" width="968" cellpadding="0" cellspacing="0">
<tr>
<td>
<table height="20" width="223" cellpadding="0" cellspacing="0">
<tr>
<td>
<font face="helvetica" size="2" color="#045FB4"><?php echo $row[0]; ?></font>
<hr size="1" color="#e6e6e6" width="100%"></hr>
</td>
</tr>
</table>
</td>
<td>
<table height="20" width="745" cellpadding="0" cellspacing="0">
<tr>
<td>
<font face="helvetica" size="2" color="black"><?php echo $row[1]; ?>
<?php echo $row[2]; ?></font>
<hr size="1" color="#e6e6e6" width="100%"></hr>
<td align="right">
<font face="helvetica" size="2" color="red">See More...</font>
<hr size="1" color="#e6e6e6" width="100%"></hr>
</td>
</tr>
</table>
</td>
</tr>
</table>
<?php
}
}
}
?>
</center>
谢谢!
詹姆斯
【问题讨论】:
-
@cypher:这可能是因为糟糕的 HTML 和糟糕的 PHP 实践。不过,这些应该只在答案中注明。这个问题仍然有效。我赞成帮助取消反对票。
-
路过投票。显然他们太懦弱了,无法发表评论。
-
我经常听到这样的话:“如果它有效(而且很容易),为什么不这样做呢?”答:更难维护。想换字体?现在你必须遍历 every 页面上的 every 字体标签。使用 CSS,您可以在 one 文件中进行 one 更改。
-
基于表格的布局也不受欢迎。
center和font已弃用,您可能想在 Google 上搜索“SQL 注入攻击”。 @ClarkeyBoy:重要的是思想。 :) -
也附议了。表格应该只用于显示数据(这就是它们的设计目的);如果您以正确的结构使用屏幕阅读器,它们会使网站更容易被屏幕阅读器的用户理解 - 例如,使用标题行的标题行,标题单元格的 th 标签,封装所有正文行的 tbody 和 tfoot页脚。 th 标签可用于列标题和行标题。尝试使用
<div style='width: 968px; margin: 0 auto;'>...</div>代替外部表(我知道那里有内联样式;我懒得在这里为它编写CSS)。