a table named users_log contains users login and logout time and date, but i am not able to sort data as i intend.
Query
mysql_query('SELECT * FROM users_log WHERE u_id = 52 ORDER BY date_log')
It sort data like
Fri 12 Jul 13 - 03:41:40 PM - 03:42:31 PM
Fri 12 Jul 13 - 05:35:40 PM - 05:42:31 PM
Sat 13 Jul 13 - 02:29:09 PM - 02:34:52 PM
users_log table
log_id, u_id, date_log, logged_date, login_time, logout_time
2, 52, 2013-01-12, Fri 12 Jul 13, 03:41:40 PM, 03:42:31 PM
as i intend to display data
Fri 12 Jul 13
03:41:40 PM - 03:42:31 PM
05:35:40 PM - 05:42:31 PM
Sat 13 Jul 13
02:29:09 PM - 02:34:52 PM
Do this:
$result = mysql_query('SELECT * FROM users_log WHERE u_id = 52 ORDER BY date_log');
$sorting = array();
while($row = mysql_fetch_assoc($result))
{
$sorting[$row['logged_date']][] = $row['login_time']."-".$row['logout_time'];
}
//Now you loop over the sorted data using foreach($sorting as $key => $value) and display it any way you want.
I hope this can be of some help.
IMHO you should do something like(i assume you want to do it in php):
SELECT date_log FROM users_log WHERE u_id = 52 GROUP BY date_log,
then iterate over results (in php) and get the corresponding rows for date:
SELECT * FROM users_log WHERE u_id = 52 AND date_log = $date_for_current_iteration ORDER BY date_log;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.