Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
Eariel19068yI don't know what engine or language is it, so I don't know what's going on, other than he's trying to find out if the current date is between the beginning of a month in certain year and the end of another month in certain year, and that it seems like there is a lot of uses of the same calls that perhaps are redundant. What is it and what's the right way?
-
It is PHP and SQL.
PHP is worse as in no validation and filtering user input. strtotime tries to parse the string given to timestamp, false on error (leading to 0 due to PHP typing, common error, validation of return value missing)
The SQL is plain broken.
Conversion / function usage leading to an expression instead of an constant makes index usage impossible.
As u started, calls are redundant.
But...
MONTH just converts to integer, so if you have a range like
'2016-08-01' to '2017-07-01'
It basically does...
08 >= MONTH(timestampColumn)
AND
07 <= MONTH(timestampColumn)
... -
@IntrusionCM
So it only compares months, at least that's what he meant. Why convert to timestamp, specially using strtotime on user input? This is wrong in so many ways 😀 -
Yes, but timestamp colum can actually have another year, I see no 'and year()='...
Ahah, I'm glad I don't have to fix it -
Yes.... That was the real big bug here....
First I thought that it was meant for month to month of the same year, looked at the form and realized....
Nope. Someone forgot something or had really no fucking clue what he was doing...
But... Why the two dates, date1 and date2 then? Really confusing. -
Period inside period?
At least what he meant, not what he wrote.
Day being 1 and 31 must be a clue, but I have no idea 😀 -
Baspar518yAnd even like this.... Adding for every year2 and month2 the day 31 is not even.... Valid...
Second rant today....
Can the class explain the following query and why I started wishing the author might suffer pain even after death?
$date1 = strtotime($_REQUEST['year1'].'-'.$_REQUEST['month1'].'-01');
$date2 = strtotime($_REQUEST['year2'].'-'.$_REQUEST['month2'].'-31');
MONTH(FROM_UNIXTIME($date1)) >= MONTH(FROM_UNIXTIME(timestampColum))
AND
MONTH(FROM_UNIXTIME($date2)) <= MONTH(FROM_UNIXTIME(timestampColum))
But... The drugs the author must have taken to write this must be frigging awesome.
undefined