Coveri Posted January 22, 2011 Share Posted January 22, 2011 month a0 a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12 a13 a14 a15 a16 a17 a18 a19 a20 a21 a22 a23 a24 a25 a26 a27 a28 a29 a30 a31 1 puudu 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 [20] [21] 22 23 24 25 [26] 27 28 29 30 31 2 puudu 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 3 puudu 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 4 puudu 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 5 puudu 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 6 puudu 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 7 puudu 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 8 puudu 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 9 puudu 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 10 puudu 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 11 puudu 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 12 puudu 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 ; i need help .. with calculating how many days are between example: january = 1 ; day =23 to feb =2; day 23 in php ... how can i do that Quote Link to comment https://forums.phpfreaks.com/topic/225327-count-mysql-tables-and-rowsneed-some-help/ Share on other sites More sharing options...
jcbones Posted January 22, 2011 Share Posted January 22, 2011 Example from the manual: <?php $january = new DateTime('2011-01-23'); $february = new DateTime('2011-02-23'); $interval = $february->diff($january); // %a will output the total number of days. echo $interval->format('%r%a total days')."\n<br />"; // While %d will only output the number of days not already covered by the // month. echo $interval->format('%m month, %d days'); ?> Quote Link to comment https://forums.phpfreaks.com/topic/225327-count-mysql-tables-and-rowsneed-some-help/#findComment-1163636 Share on other sites More sharing options...
Coveri Posted January 22, 2011 Author Share Posted January 22, 2011 yeah but i wanted to know if there is a way to count them in my db ... btw that is my db . And sry about my enhlish Quote Link to comment https://forums.phpfreaks.com/topic/225327-count-mysql-tables-and-rowsneed-some-help/#findComment-1163701 Share on other sites More sharing options...
ManiacDan Posted January 22, 2011 Share Posted January 22, 2011 Why would you design a database like this? Are you planning on the number of days in March changing in the near future? Are you going to run a calendar that's different from everyone else's? To my knowledge, there is no way to easily write this query. You COULD use a very (very) long series of IF statements that progressively add 1 to a variable if the column is populated for a specific row, but you'd have to build the query itself in PHP anyway. MySQL offers the DATEDIFF function, but your table is very poorly constructed...and you don't actually NEED a table to use the datediff function. -Dan Quote Link to comment https://forums.phpfreaks.com/topic/225327-count-mysql-tables-and-rowsneed-some-help/#findComment-1163703 Share on other sites More sharing options...
Coveri Posted January 22, 2011 Author Share Posted January 22, 2011 Im making a calendar that shows if date is available or not ... and there is a drop down menu for date selection . And like you see im new at this! Quote Link to comment https://forums.phpfreaks.com/topic/225327-count-mysql-tables-and-rowsneed-some-help/#findComment-1163706 Share on other sites More sharing options...
ManiacDan Posted January 22, 2011 Share Posted January 22, 2011 Don't write your own date functions. PHP has DateTime::diff. MySQL has DATEDIFF. There is absolutely no reason for you to attempt to write your own date/time functions. This is how you build a calendar: Each "event" entry has an "event date," plus a title and a description. Select all the events from a specific month you wish to display. Sort by start date. Loop through the days of the month (using PHP) and print the calendar, moving to a new row once you hit a the end of the week. Use the PHP functions strtotime and date to determine what day of the week you're on. For each day, check to see if there are any events in your result set that fall inside that day. If so, print them. You should be able to make a calendar without any hard-coded days of the month. This MySQL table is completely unnecessary, I recommend you delete it now. -Dan Quote Link to comment https://forums.phpfreaks.com/topic/225327-count-mysql-tables-and-rowsneed-some-help/#findComment-1163707 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.