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;
}

September 16 2013

Remove GUI (GDM, Gnome, X Window) from CentOS

Tagged Under :

Linux
If you install a CentOS server, but accidently also installed Desktop Environment such as GDM, GNOME or X Window, you can easily remove the GUI packages and return back to Command Line (CLI).

There are two ways to do that. You can simply disable GUI or completely uninstall it. I will provide steps to do both.

Temporary Disable GUI (GDM)
Open inittab with nano
nano /etc/inittab
change
id:5:initdefault:
to
id:3:initdefault:

Remove GUI

September 16 2013

Retrieving the last record in each group

Tagged Under : ,

MySQL
Sometimes we keep all the records/logs in one table. But if we want retrieve each group last records in one SQL it look like impossible.

Below Example showed how to:
SELECT rs1.*
FROM TABLE rs1 LEFT JOIN TABLE rs2
  ON (rs1.name = rs2.name AND rs1.id < rs2.id)
WHERE rs2.id IS NULL;
Above method can get the last record results group by name.

If you want retrieve first records in each group, just change to

August 11 2013

Tidesdk display phpinfo and php exntersion

Tagged Under : ,

TideSDK
In here, I am showing you how to use TideSDK to display the phpinfo() and available php extension in your application.

First, use the TideSDK Developer to create a new application. After that, open the index.html file and edit the source.

In this example, I use JQuery to call the phpinfo(). So we need include the JQuery as well.

Include the JQuery inside the head.
<head>
<script src="jquery-2.0.1.min.js"></script>
</head>
We need include another PHP class to call the phpinfo() script to display the information. include the PHP file in head as well.
<head>
<script src="jquery-2.0.1.min.js"></script>
<script type="text/php" src="info.php"></script>
</head>

July 20 2013

Linux Default Gateway IP Address

Tagged Under :

Linux
In Windows Machine if want to check our IP Address or Gateway the easy method is use Command Prompt type ipconfig then it will lists down everything. But in LINUX it different.

In Linux, they call it ifconfig, open the terminal and type ifconfig it will lists down all the available network. But it didn’t print out the Gateway IP Address.

The easy way to print out Gateway IP Address command.
route -n | grep 'UG[ \t]' | awk '{print $2}'
Or, you can use others command to print out the Gateway.