Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/283.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
“制作内容”;饲料“;使用mysql数据库和php,这是一种安全的方法吗?_Php_Mysql_Database_Feed - Fatal编程技术网

“制作内容”;饲料“;使用mysql数据库和php,这是一种安全的方法吗?

“制作内容”;饲料“;使用mysql数据库和php,这是一种安全的方法吗?,php,mysql,database,feed,Php,Mysql,Database,Feed,我正在制作一个侧栏提要,它将显示提交到数据库中的10个最新内容。我对这一切都很陌生,所以我想。。这样做行吗?它起作用了。。不是自动提交的,但当我向数据库中提交某个内容时,它就会进入数据库。。我提交其他内容,然后顶部转到第二个。。!我无法摆脱这样的感觉,也许这不是一个好办法 前三部分 <div class="span3 offset3"> <?php include 'feed/one.php'; ?> <ul class="nav nav-list we

我正在制作一个侧栏提要,它将显示提交到数据库中的10个最新内容。我对这一切都很陌生,所以我想。。这样做行吗?它起作用了。。不是自动提交的,但当我向数据库中提交某个内容时,它就会进入数据库。。我提交其他内容,然后顶部转到第二个。。!我无法摆脱这样的感觉,也许这不是一个好办法

前三部分

<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 } ?>


提交的数据将显示在我的主页上,直到提交了其他内容,然后转到“提要”,并转到另一个显示过去数据的页面

与每次查询数据库并获取一条记录来显示它不同,您应该在一次查询中执行此操作,以获取所需的行数:

<?php $data = $mysqli->query("SELECT * FROM hit ORDER BY hit_id DESC LIMIT 1, N"); ?> 


这将获取前N行,其中N当然必须是数字。然后,您应该循环抛出行并按现在的方式打印。唯一的区别是,您可能需要一段时间才能正确地了解打开/循环/关闭表的细微差别,但这确实是一项很好的时间投资,可以让您全神贯注于此

您似乎没有任何用户可以拦截的内容,因此“安全”不是问题

但你的质疑是不合逻辑的。当您可以最初获取数据并使用该对象在需要的地方中继内容时,没有理由在页面上重复具有多个偏移量的相同查询。在文件开头运行类似这样的查询,或者最好在呈现任何输出之前运行

"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>
现在,这里有一些标记错误。你关上一张从未打开过的桌子。这只能在很小的程度上被视为表格数据,因此无论如何,表格可能不是实现这一点的最佳方式。我自己也不明白你用这种方式使用th和td,但如果它对你有用,那就好了


您应该跳出php来显示html。像
这样的回音是完全没有必要的。

您实际上是在使用
点击id
字段来对从数据库获取的数据进行排序

如果您确实想要检索“提交到我的数据库中的10个最新内容”,您需要的不是自动递增的ID(类似于
数量
行上的
计数
)。它将取决于填充此字段的实际值/方式,但它可能看起来像这样:

SELECT * FROM hit GROUP BY Category ORDER BY amount DESC;
关于本部分:

但是当我把一些东西提交到我的数据库中时,它就在那里了。。我 提交其他内容,然后顶部转到第二个

原因很简单,您使用的是按hit_id DESC排序,这就是为什么最后一个插入的id排在第一位