How to disable SELECT QUERY from auto-sorting the results

时间:2022-10-13 12:26:34
<?php
            $db = db_connect();
            $SQLSELECT = "SELECT * FROM `order` INNER JOIN tb ON order.pc = tb.pc";
            $result_set =  mysqli_query($db, $SQLSELECT);
            foreach($result_set as $row) {
            ?>
                <tr>
                    <td><?php echo $row['Name']; ?></td>
                    <td><?php echo $row['add1']; ?></td>
                    <td><?php echo $row['add2']; ?></td>
                    <td><?php echo $row['prov']; ?></td>
                    <td><?php echo $row['pc']; ?></td>
                    <td><?php echo $row['tier']; ?></td>
                </tr>
            <?php

I have this code and it gets data from the database by comparing the 2 tables. So for example the one in order table is 5,6,2,1,4,3. So when the query compares the 2 tables it checks for 5 then 6 then 2 and so on. When the results come out, the results become sorted and the output becomes 1,2,3,4,5,6 but I want to output it in the order how I input it. It is somehow auto sorting. Is it possible to disable that?

我有这个代码,它通过比较2个表从数据库中获取数据。例如,订单表中的一个是5,6,2,1,4,3。因此,当查询比较2个表时,它检查5然后是6然后是2,依此类推。当结果出来时,结果将被排序,输出变为1,2,3,4,5,6,但我想按照输入的顺序输出结果。它以某种方式自动排序。有可能禁用它吗?

1 个解决方案

#1


1  

Unless you explicitly specify a sort order with the user of ORDER BY. Mysql and other databases does not provide any guarantee about the order in what the data is returned.

除非您使用ORDER BY用户明确指定排序顺序。 Mysql和其他数据库不提供有关返回数据的顺序的任何保证。

If you have a table that hasn't had many deletes and updates, the order is likely the order that you inserted. But no guarantee. So use ORDER BY

如果您的表没有很多删除和更新,则订单很可能是您插入的订单。但不能保证。所以使用ORDER BY

#1


1  

Unless you explicitly specify a sort order with the user of ORDER BY. Mysql and other databases does not provide any guarantee about the order in what the data is returned.

除非您使用ORDER BY用户明确指定排序顺序。 Mysql和其他数据库不提供有关返回数据的顺序的任何保证。

If you have a table that hasn't had many deletes and updates, the order is likely the order that you inserted. But no guarantee. So use ORDER BY

如果您的表没有很多删除和更新,则订单很可能是您插入的订单。但不能保证。所以使用ORDER BY