Jump to content

Barand

Moderators
  • Posts

    24,566
  • Joined

  • Last visited

  • Days Won

    822

Everything posted by Barand

  1. When I need to extract chart data covering a range of dates I find it easier to create a temporary table containing all the dates that I need to show on the chart. I use a DatePeriod object to create the range of dates EG mysql> select * from tempdate; +---------+ | month | +---------+ | 2016-01 | | 2016-02 | | 2016-03 | | 2016-04 | | 2016-05 | | 2016-06 | | 2016-07 | | 2016-08 | | 2016-09 | | 2016-10 | | 2016-11 | | 2016-12 | +---------+ So if I have a revenue table like yours ... mysql> select * from revenue; +---------+---------+ | month | revenue | +---------+---------+ | 2016-05 | 20 | | 2016-08 | 10 | | 2016-11 | 50 | +---------+---------+ ... I can fill in the gaps with SELECT t.month , IFNULL(r.revenue, 0) as revenue FROM tempdate t LEFT JOIN revenue r USING (month); +---------+---------+ | month | revenue | +---------+---------+ | 2016-01 | 0 | | 2016-02 | 0 | | 2016-03 | 0 | | 2016-04 | 0 | | 2016-05 | 20 | | 2016-06 | 0 | | 2016-07 | 0 | | 2016-08 | 10 | | 2016-09 | 0 | | 2016-10 | 0 | | 2016-11 | 50 | | 2016-12 | 0 | +---------+---------+
  2. use a foreach() loop or print_r()
  3. Simpler: $outp = $result->fetch_all(MYSQLI_ASSOC); echo json_encode($outp);
  4. Locking - OP has opened separate thread.
  5. You have the variable inside single quotes - remove them. (The value it is looking for is the literal string $-k-e-y instead of the variable's value)
  6. I'd separate the time check from the day check if it is a work day if it is work hour we are open else we are closed endif else we are closed endif
  7. So for it to work as it did with a separate time column, are the time elements the same in the two datetime columns? When comparing a date with a datetime column you need to use only the date portion of the datetime. So if my opening assumption is true SELECT id , schedule_start , schedule_end WHERE UTC_DATE() BETWEEN DATE(schedule_start) AND DATE(schedule_end) AND EXTRACT(HOUR_MINUTE FROM UTC_TIME()) = EXTRACT(HOUR_MINUTE FROM schedule_start)
  8. No one that understands the sanity in adding two dates.
  9. Foreach () takes an array and loops through it. You have the array, $dpts, from which you created the comma-delimited string $departmento.
  10. Use code tags ( <> button in toolbar) when posting code. lol
  11. You are getting an error on $_REQUEST['step'] So perhaps that is is the one you should be checking with isset() ?
  12. If you can't remember the manual is there to jog your memory
  13. Change 'options' => array_values($category_str) to 'options' => $category_str;
  14. for ($i=$y+1; $i >= $y-11; $i--)
  15. There are several things in this job that can lead to insanity. One of them is accepting free-form text as input. It only takes a small spelling mistake (like your "strops" above) and the whole thing collapses like a house of cards.
  16. It could be they have an ancient version of PHP that doesn't support [..] array definition syntax. To verify try array( 'id' => $_GET['id']) instead of [ 'id' => $_GET['id'] ]
  17. Rerunning #3, #4, #5 is a definite no-no. You could end up with completely different set of ids. That was, as previously stated, a one-off exercise. How do you create the csv at present? How many test_db records do you typically add at a time? How often do you have new whiskies?
  18. You could try reading thara's post again and use the function he gave you. edit - alternatively you can do it in PHP $dtobj = new DateTime($row['date']); echo $dtobj->format('d/m/Y'); //--> 23/01/2017, for example
  19. That is what that query was designed to do - just the latest record with price and date plus the average price. When you list all the results for a whisky, what do you want to show?
  20. Sorry, I forgot to change it to INNER JOIN in that last version of the query.
  21. There is a "Donate to me" link underneath my avatar on the left. Thanks.
  22. url_img and whsky_id are not in the fields selected in the query.
  23. You have left the id hard coded instead of " = :id ". This version below may also be more efficient SELECT w.whisky_name , price , date , avprice FROM test_db t JOIN whisky w USING (whisky_id) JOIN ( SELECT whisky_id , AVG(price) as avprice FROM test_db WHERE whisky_id = :id GROUP BY whisky_id ) avcalc USING (whisky_id) ORDER BY date DESC LIMIT 1;
  24. Then SELECT w.whisky_name , price , date , avprice FROM test_db t JOIN whisky w USING (whisky_id) JOIN ( SELECT whisky_id , AVG(price) as avprice FROM test_db GROUP BY whisky_id ) avcalc USING (whisky_id) WHERE w.whisky_id = 1 ORDER BY date DESC LIMIT 1;
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.