请问我在更新后遇到有关记录顺序的问题。
我有两页home.php
和settings.php
。
home.php
包含来自mysli选择查询的结果。
$getid = $getdata['user_id'];
$query = mysqli_query($con,"SELECT * FROM posts
WHERE `user_id` = ' $get_id'
ORDER BY date_added DESC
LIMIT 15 ");
所选记录为id
username
notes
date_added
,这些记录以desc
顺序成功显示。
在我的settings.php
我允许用户更新用户名,同时更新用户名时,我还会运行更新查询,更改notes
表上的用户名。在user
表和notes
表上都成功更新了新用户名。但不幸的是,当我回到home.php
时,笔记不会再次以desc
的顺序显示。它正在显示表格顶部的注释。
更新查询功能(从settings.php
调用):
function update_user($update_data){
$con = db();
global $session_user_id;
$update= array();
array_walk($update_data, 'array_sanitize');
foreach ($update_data as $field => $data) {
$update[] = '`'. $field . '` =\''.$data .'\'';
}
mysqli_query($con,"UPDATE `users` SET "
. implode(', ', $update) . ,
" WHERE `user_id` = '$session_user_id'");
mysqli_query($con,"UPDATE notes SET username =
(SELECT `username`
FROM users
WHERE user_id = $session_user_id
)
WHERE user_id = $session_user_id ");
}
我尝试按date_added
排序,但它还没有正常工作。
请帮助我,谢谢。
答案 0 :(得分:0)
you have to change date format to UNIX_TIMESTAMP to apply order by in
query
$query = mysqli_query($con,"SELECT * ,UNIX_TIMESTAMP(date_added) as date FROM posts
WHERE `user_id` = ' $get_id'
ORDER BY date DESC
LIMIT 15 ");