Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- VISITORS TBL
- ID product_id hits date
- 130 1 1 2012-08-11
- 94 810 53 2012-08-06
- 95 810 32 2012-08-07
- 96 810 22 2012-08-09
- 97 810 13 2012-08-10
- 98 810 16 2012-08-11
- 99 810 13 2012-08-22
- <?
- $rs = mysql_query("SELECT hits,date FROM visitors WHERE product_id=81 AND date BETWEEN 2012-08-01 AND 2012-08-31 ORDER BY date ASC");
- $flot = array();
- $last_date = '2012-08-00';
- $day = 1;
- if ($rs && mysql_num_rows($rs)) {
- while ($row = mysql_fetch_array($rs)) {
- $days_since = check_days_since($row['date'], $last_date);
- print $row['date'] . '|' . $last_date . '|' . $days_since . "n";
- if ($days_since) {
- for ($i = 1; $i < $days_since; $i++) {
- $flot[] = array($day++, 0);
- }
- }
- $flot[] = array($day++, $row['hits']);
- $last_date = $row['date'];
- }
- }
- print json_encode($flot);
- function check_days_since($new, $old) {
- if (!$new || !$old) return 1;
- return (strtotime($new) - strtotime($old)) / (60*60*24);
- }
- ?>
Add Comment
Please, Sign In to add comment