Scorptique Posted December 6, 2008 Share Posted December 6, 2008 Hey all, I need help understand the codes. This set of codes work, they basically display the upcoming birthdays from my contact list. $sql = "select cl_id, cl_fname, cl_lname, cl_email, date_format(cl_dob, '%d %b %Y') AS cl_dob, (TO_DAYS((cl_dob + INTERVAL (YEAR(CURRENT_DATE)-YEAR(cl_dob) + (RIGHT(CURRENT_DATE,5)> RIGHT(cl_dob,5))) YEAR)) - TO_DAYS(CURRENT_DATE)) as daysAway from contact_list where username = '$username' order by daysAway DESC"; But...i dont really understand (TO_DAYS((cl_dob + INTERVAL (YEAR(CURRENT_DATE)-YEAR(cl_dob) + (RIGHT(CURRENT_DATE,5)>RIGHT(cl_dob,5))) YEAR)) - TO_DAYS(CURRENT_DATE)). if you understand, can you explain to me please? Thanks! ^^;; Quote Link to comment https://forums.phpfreaks.com/topic/135819-solved-help-me-understand-what-these-codes-mean/ Share on other sites More sharing options...
Mchl Posted December 6, 2008 Share Posted December 6, 2008 They're all explained here If you have specific questions about any one function, ask. Quote Link to comment https://forums.phpfreaks.com/topic/135819-solved-help-me-understand-what-these-codes-mean/#findComment-707900 Share on other sites More sharing options...
Scorptique Posted December 6, 2008 Author Share Posted December 6, 2008 Hm, I understand the individual functions, but I can't seem to comprehend how it works as a whole...especially for this part. (TO_DAYS((cl_dob + INTERVAL (YEAR(CURRENT_DATE)-YEAR(cl_dob) + (RIGHT(CURRENT_DATE,5)> RIGHT(cl_dob,5))) YEAR)) - TO_DAYS(CURRENT_DATE)) Quote Link to comment https://forums.phpfreaks.com/topic/135819-solved-help-me-understand-what-these-codes-mean/#findComment-707904 Share on other sites More sharing options...
Mchl Posted December 6, 2008 Share Posted December 6, 2008 So let's take it from outside to inside If you drop outermost parentheses (), you will see, that there are two TO_DAYS() functions TO_DAYS((cl_dob....) - TO_DAYS(CURRENT_DATE) So, we have a number of days since year 0 calculated for the some date in the first function, and then number of days since year 0 for today substracted from it. So basically it is a number of days between tha date in first function, and today. Let's go some deeper into this first TO_DAYS() function cl_dob + INTERVAL (YEAR(CURRENT_DATE)-YEAR(cl_dob) + (RIGHT(CURRENT_DATE,5)>RIGHT(cl_dob,5))) YEAR So we now have two expressions added together. cl_dob This comes from table INTERVAL (YEAR(CURRENT_DATE)-YEAR(cl_dob) + (RIGHT(CURRENT_DATE,5)>RIGHT(cl_dob,5))) This one is strange, because INTERVAL() should have at least two arguments... you sure this is right? Quote Link to comment https://forums.phpfreaks.com/topic/135819-solved-help-me-understand-what-these-codes-mean/#findComment-707922 Share on other sites More sharing options...
Scorptique Posted December 6, 2008 Author Share Posted December 6, 2008 o. I really dont know =/ And i found out that the codes aren't working right.... =( But I did copy that complicated section exactly from the example codes. Quote Link to comment https://forums.phpfreaks.com/topic/135819-solved-help-me-understand-what-these-codes-mean/#findComment-707927 Share on other sites More sharing options...
Mchl Posted December 6, 2008 Share Posted December 6, 2008 Well... It should not be working. I just tested and INTERVAL() throws an error, when only one argument is passed. Quote Link to comment https://forums.phpfreaks.com/topic/135819-solved-help-me-understand-what-these-codes-mean/#findComment-707929 Share on other sites More sharing options...
Scorptique Posted December 6, 2008 Author Share Posted December 6, 2008 Oh man, sorry to take up your time. Now I need to post another post to ask how to create a statement that works D= Quote Link to comment https://forums.phpfreaks.com/topic/135819-solved-help-me-understand-what-these-codes-mean/#findComment-707937 Share on other sites More sharing options...
Mchl Posted December 6, 2008 Share Posted December 6, 2008 No problem. If you need to understand such statements, do it as we started doing it here. Try to find out, what is on the outside, and then go deeper and deeper inside. Quote Link to comment https://forums.phpfreaks.com/topic/135819-solved-help-me-understand-what-these-codes-mean/#findComment-707960 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.