简体   繁体   English

PHP MySQL查询以奇怪的顺序显示结果

[英]PHP MySQL query displaying results in weird order

I have two sets of 4 rating inputs in a database table, one with a priority_id of 19 and the other with the priority_id of 20. If I run the sql query below in phpMyAdmin it will return the values for the id primary key field and list them in the right order. 我在数据库表中有两组4个等级输入,一组的priority_id为19,另一组的priority_id为20。如果我在phpMyAdmin中运行以下sql查询,它将返回id主键字段和列表的值他们以正确的顺序。 If I run my php file and select the values for priority_id 19 they display to the screen in the right order. 如果我运行我的php文件并选择priority_id 19的值,它们将以正确的顺序显示在屏幕上。 However, if I select the values for priority_id 20 the id values display to screen in a weird, irrational order. 但是,如果我选择priority_id 20的值,则id值将以怪异,不合理的顺序显示在屏幕上。 Anyone have ideas what might be causing this? 任何人都知道可能是什么原因造成的? I've tried adding the order by to the sql query but that doesn't seem to help. 我尝试将order by添加到sql查询,但这似乎无济于事。

$input_ids = array();

$query = "SELECT * FROM rating_inputs WHERE priority_id = '20'";
echo $query . "<br/>";

$result = mysql_query($query);
$z=0;
while($row=mysql_fetch_assoc($result)){
    $input_ids[$z] = $row['id'];
    echo "input id: " . $input_ids[$z] . "<br/>";
    $z=$z+1;
}

These are my database fields and their data. 这些是我的数据库字段及其数据。 The value field is empty at the moment. 值字段目前为空。

id | id | priority_id | priority_id | category_id | category_id | value

53 | 19 | 1  |
54 | 19 | 4  |
55 | 19 | 10 | 
56 | 19 | 11 | 
57 | 20 | 1  | 
58 | 20 | 4  | 
59 | 20 | 10 | 
60 | 20 | 11 | 

Records have no intrinsic order in the database. 记录在数据库中没有固有顺序。 The order in which they're retrieved is random for all intents and purposes. 出于所有意图和目的,检索它们的顺序都是随机的。 If they are in any particular order, it's because they happened to be stored in that order or were encountered in the index in that order. 如果它们以任何特定顺序排列,那是因为它们碰巧是按该顺序存储或在索引中按该顺序遇到的。

If you expect a particular order, use an ORDER BY clause in the query. 如果期望特定的顺序,请在查询中使用ORDER BY子句。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM