我有一个用 PHP 和 MySQLi 填充的简单表。该表仅包含一个我设置为主键以避免重复的字段。一切正常,除了 MySQLi 按字母顺序对输入进行排序,即使我没有以这种方式将它们放入数据库。我想稍后从表中拉出,并按照我将项目放入数据库中的确切顺序来回显所有内容。
有没有办法轻松完成这项工作?我必须使用不同的字段作为主键吗?
$mysqli = connect_db();
$mysqli->query('TRUNCATE TABLE things');
$things = [bat, cat, apple, zero];
for($i = 0; $i < count($things); $i++){
$query = $mysqli->prepare('INSERT INTO things (name) VALUES (?)');
$query->bind_param('s', $things[$i]);
$query->execute();
$query->close();
}
$mysqli->close();
// The table puts them in the following order: apple, bat, cat, zero