Guest User

Untitled

a guest
Jan 17th, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. VISITORS TBL
  2. ID product_id hits date
  3. 130 1 1 2012-08-11
  4. 94 810 53 2012-08-06
  5. 95 810 32 2012-08-07
  6. 96 810 22 2012-08-09
  7. 97 810 13 2012-08-10
  8. 98 810 16 2012-08-11
  9. 99 810 13 2012-08-22
  10.  
  11. <?
  12. $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");
  13. $flot = array();
  14. $last_date = '2012-08-00';
  15. $day = 1;
  16.  
  17. if ($rs && mysql_num_rows($rs)) {
  18. while ($row = mysql_fetch_array($rs)) {
  19. $days_since = check_days_since($row['date'], $last_date);
  20. print $row['date'] . '|' . $last_date . '|' . $days_since . "n";
  21.  
  22. if ($days_since) {
  23. for ($i = 1; $i < $days_since; $i++) {
  24. $flot[] = array($day++, 0);
  25. }
  26. }
  27.  
  28. $flot[] = array($day++, $row['hits']);
  29. $last_date = $row['date'];
  30. }
  31. }
  32.  
  33. print json_encode($flot);
  34.  
  35.  
  36. function check_days_since($new, $old) {
  37. if (!$new || !$old) return 1;
  38. return (strtotime($new) - strtotime($old)) / (60*60*24);
  39. }
  40. ?>
Add Comment
Please, Sign In to add comment