javascript - After adding or deleting, the detected data is not sorted normally. How to solve it?
曾经蜡笔没有小新
曾经蜡笔没有小新 2017-05-16 12:58:26
0
2
548

I have recently encountered a lot of problems when I am new to PHP. The information I checked online is incomplete or I cannot understand it. I have to ask you to help me solve these problems. Thank you!

Problem: After adding or deleting, the queried data is not sorted properly and is all messed up. How to solve it?


Here is my php:

//查询方法
    function init_data_list(){
        //测试 运行crud.html时是否可以获取到 下面这个字符串
        /*echo "46545465465456465";*/
        
        //查询表
        $sql = "SELECT * FROM `t_users`";
        $query = query_sql($sql);
        while($row = $query->fetch_assoc()){
            $data[] = $row;
        }
        
        $json = json_encode(array(
            "resultCode"=>200,
            "message"=>"查询成功!",
            "data"=>$data
        ),JSON_UNESCAPED_UNICODE);
        
        //转换成字符串JSON,并输出
        echo($json);
    }

    function query_sql(){
        $mysqli = new mysqli("127.0.0.1", "root", "root", "crud");
        $sqls = func_get_args();
        foreach($sqls as $s){
            $query = $mysqli->query($s);
        }
        $mysqli->close();
        return $query;
    }

I found that I need to use sql’s order by id to sort. How should I use this statement?
I added the following statement, and a 500 error was reported!

$sql = "SELECT * FROM `t_users` ORDER BY ID"; //500错误

The table structure of t_user is as follows:


How should I add this sorting statement? Thanks!

曾经蜡笔没有小新
曾经蜡笔没有小新

reply all(2)
Peter_Zhu

Send out the table structure of t_user and take a look. Ying
should not be ID but id, right?

给我你的怀抱

I found that I need to use sql’s order by id to sort. How should I use this statement? I added the following statement, and a 500 error was reported!

$sql = "SELECT * FROM `t_users` ORDER BY ID"; //500错误

The reason for the error: Sort according to the id in the table, but there is no ID field in the table. The ID in this table is user_id, so this sql statement should be written like this:

$sql = "SELECT * FROM `t_users` ORDER BY user_id";  //正确的排序方式
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template