My mySQL table is as below
id - hash - page - timestamp
1 - ig35sdf89 - page1 - 2015-05-06 12:03:54
2 - ig35sdf89 - page2 - 2015-05-06 12:06:54
3 - ig35sdf89 - page1 - 2015-05-06 12:08:54
4 - xgd98rgf - page1 - 2015-05-06 12:10:54
5 - aaaat43gr - page3 - 2015-05-06 12:12:54
My question is what is a mySQL query to use so as to show something like where I will show the path of each hash order by his timestamp:
ig35sdf89 - page1 - 2015-05-06 12:08:54
- page2 - 2015-05-06 12:03:54
- page1 - 2015-05-06 12:06:54
xgd98rgf - page1 - 2015-05-06 12:10:54
aaaat43gr - page3 - 2015-05-06 12:12:54
here is the until now code
$sql= mysql_query("SELECT IF(@tempHash = `hash`, '', @tempHash := `hash`) `hash`, page, `timestamp`
FROM behaviour
JOIN (SELECT @tempHash := '')s
ORDER BY `timestamp`
");
while($row = mysql_fetch_array($sql)) {
echo '<tr><td>'.$row[hash].'</td><td>'.$row[page].'</td><td>'.$row[timestamp].'</td></tr>';
}
The problem is that the output even though it runs, it has a bug. The path (pages) of hash abc
are splitted. I mean that it displays a number of pages from abc
hash, then a user xxx123
is shown with xxx123
pages and then it continues with user abc
. What I want is full list of abc
pages, timestamps and then proceed to xxx123
and so on.
I noticed in thatthat the splitting is made because of timestamps.
if user1
has a page timestamp 14:10:12 and the next 14:10:30 and user2
has 14:10:20 it will break the path of user1
, show user2
and then continue with user1
.