October 26 2013

php get first and last date of the month

Tagged Under :

php
My application always need get first and last month of the date when user given a date to my system. it look like very trouble but actually quite easy only.

From here I show you how to get first and last of the date in current month.
//last day of the month
date("Y-m-t");
//first day of the month
date("Y-m-1");
Why using t in last day of the month, it is because in PHP date function “t” will return you Number of days in the given month.

And now we try get first and last date of the month from the last month.

October 26 2013

Mysql last day of the month

Tagged Under : ,

MySQL
Because sometimes need to know last day of the previous month, and I was using procedure/routine to completed the query. That’s the reason I can’t use others programming language to do it. All the thing must finish in MySQL server only.

And very lucky, MySQL have “last_day()” function to get last day of the month.

Below example are showing how to use it.

October 26 2013

Can’t drop database ‘dbname’; database doesn’t exist and database exists

Tagged Under : ,

MySQL
Recently I reinstall MySQL Database because it suddenly cannot start and it crash. After I successful reinstall, I found an extra database in MySQL Server.

When I tried to drop the database, I received the following error:
“Can’t drop database ‘dbname’; database doesn’t exist”
And when I tried to create a new database with same name, it told me:
“Can’t create database ‘dbname’; database exists”
That just didn’t make any sense! And the PHPMyAdmin application still listed the database in the Catalog list.

October 15 2013

ASP.net Model Class and Data context class do not list the Movie selections

Tagged Under :

asp.net
I’m working through ASP.NET MVC4 tutorial and the section “Accessing Your Model’s Data from a Controller”. I’ve attempted to add the MoviesController but the combo boxes for Model Class and Data context class do not list the Movie selections that they specified.



It is because I not yet rebuild the application and the tutorial also didn’t mention this.

October 05 2013

Yii different controller return different error page

Tagged Under :

Yii
Because need develop an APi application with frontend and backend together.

Frontend without any interface and it just return JSON format to the user. But backend have interface to let user do the setting and update data.

In Yii main.php only allow set one error page. The solution is set the error page in controller class.

You can follow below example to write your own error page to each controller.

October 05 2013

Yii cgridview show first and last page in pagination

Tagged Under :

Yii
Default Yii cgridview pagination didn’t show the first and last page. But actually it was hidden but the CSS class, the easy method is change the CSS class to let it can show it.



how to do it? open pager.css file and find the code like below.

Controller error handler:
ul.yiiPager .first, ul.yiiPager .last {
    display: none;
}