function post_data($update_data){
$session_user_id = $_SESSION ['user_id'];
$user_data = user_data($session_user_id, 'username', 'email');
$email= $user_data['email'];
$update= array();
array_walk($update_data, 'array_sanitize');
foreach ($update_data as $field => $data) {
$update[] = '`'. $field . '` =\''.$data .'\'';
}
mysql_query("UPDATE `user_post` SET " . implode(', ', $update) . " WHERE `email` = '$email' ORDER BY date_added DESC ");
}
嗨,上面的函数更新了一个mysql表,请问如何确保代码执行时,按照上次插入的顺序显示。
这是从表中获取值的代码;
$query = mysql_query("SELECT * FROM user_post WHERE `username` = '$get_user' ORDER BY date_added DESC LIMIT 3 ");
$newsCount = @mysql_num_rows($query); // count the output amount
if ($newsCount > 0) {
while($row = mysql_fetch_assoc($query)){
$id = $row["id"];
$username = $row["username"];
$body = $row["body"];
$profile_pix = $row["profile_pix"];
$date_added = strftime("%b %d, %Y", strtotime($row["date_added"]));
}
}
感谢。
答案 0 :(得分:0)
我认为您可以在表格中添加“created_at”列,然后按“created_at”排序查询。