我正在制作一个侧栏提要,它将显示提交到我的数据库中的 10 个最新内容。我对这一切都很陌生,所以我想知道..这是一种好的方法吗?它可以工作..不是自动的,但是当我将某些内容提交到我的数据库中时,它会在那里..我提交其他内容,然后顶部转到第二个..!我只是无法摆脱这种感觉,也许这不是一个好方法。
前 3 个部分
<div class="span3 offset3">
<?php include 'feed/one.php'; ?>
<ul class="nav nav-list well">
<li class="nav-header"></li>
<li class="active"><a href="#">HIT INFO</a></li>
<?php while($row = $data->fetch_assoc()) { ?>
<li><a href="<?php print $row['link']?>"><?php
Print "<tr>";
Print "<th>Hit:</th> <td>".$row['hit'] . "</td> ";
Print "<th>Amount:</th> <td>".$row['amount'] . " </td>";
Print "<th>Category:</th> <td>".$row['category'] . "</td></tr> ";
Print "<br><br/>";
Print "</table>";?></a></li>
<?php } ?>
<li class="divider"></li>
<?php $data = $mysqli->query("SELECT * FROM hit ORDER BY hit_id DESC LIMIT 1, 1"); ?>
<?php while($row = $data->fetch_assoc()) { ?>
<li><a href="<?php print $row['link']?>"><?php
Print "<tr>";
Print "<th>Hit:</th> <td>".$row['hit'] . "</td> ";
Print "<th>Amount:</th> <td>".$row['amount'] . " </td>";
Print "<th>Category:</th> <td>".$row['category'] . "</td></tr> ";
Print "<br><br/>";
Print "</table>";?></a></li>
<?php } ?>
<li class="divider"></li>
<?php $data = $mysqli->query("SELECT * FROM hit ORDER BY hit_id DESC LIMIT 2, 1"); ?>
<?php while($row = $data->fetch_assoc()) { ?>
<li><a href="<?php print $row['link']?>"><?php
Print "<tr>";
Print "<th>Hit:</th> <td>".$row['hit'] . "</td> ";
Print "<th>Amount:</th> <td>".$row['amount'] . " </td>";
Print "<th>Category:</th> <td>".$row['category'] . "</td></tr> ";
Print "<br><br/>";
Print "</table>";?></a></li>
<?php } ?>
<li class="divider"></li>
<?php $data = $mysqli->query("SELECT * FROM hit ORDER BY hit_id DESC LIMIT 3, 1"); ?>
<?php while($row = $data->fetch_assoc()) { ?>
<li><a href="<?php print $row['link']?>"><?php
Print "<tr>";
Print "<th>Hit:</th> <td>".$row['hit'] . "</td> ";
Print "<th>Amount:</th> <td>".$row['amount'] . " </td>";
Print "<th>Category:</th> <td>".$row['category'] . "</td></tr> ";
Print "<br><br/>";
Print "</table>"; ?></a></li>
<?php } ?>
提交的数据会显示在我的主页上,直到提交其他内容为止,转到“提要”,并且还会转到显示过去数据的另一个页面。
最佳答案
您似乎没有任何用户可以拦截的内容,因此“安全”不是问题。
不过,您的查询不合逻辑。当您最初可以获取数据并使用该对象在需要的地方中继内容时,没有理由在整个页面上使用多个偏移量重复相同的查询。在文件开头运行这样的查询,或者最好在呈现任何输出之前运行。
"SELECT * FROM hit ORDER BY hit_id DESC LIMIT 4"
现在您有 4 个项目,因此在整个页面中访问这些项目可能如下所示:
<ul class="nav nav-list well">
<li class="nav-header"></li>
<li class="active"><a href="#">HIT INFO</a></li>
<?php while($row = $data->fetch_assoc()): ?>
<li>
<a href="<?php print $row['link']?>">
<table>
<tr>
<th>Hit:</th> <td><?php echo $row['hit']; ?></td>
<th>Amount:</th> <td><?php echo $row['amount']; ?></td>
<th>Category:</th> <td><?php echo $row['category']; ?></td>
</tr>
<br><br/>
</table>
</a>
</li>
<li class="divider"></li>
<?php endwhile; ?>
</ul>
现在,您有一些标记错误。您关闭了一张从未打开过的 table 。这只能在很小的程度上被视为表格数据,因此无论如何,表格可能不是实现此目的的最佳方法。我本人不理解您以这种方式使用 th 和 td,但如果它对您有用那就太好了。
您应该脱离 php 来显示 html。回显类似 "<th>"
的内容完全没有必要。
关于php - 用mysql数据库和php制作内容 "feed",这是安全的方法吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16369788/