Get Column Values As Comma Separated String In MySQL

While working on a project I was required to display the data fetched from a column in form of comma separated values. With couple of Google searches I was able able to land on a solution.

You can easily perform this task using MySQL’s GROUP_CONCAT function.

Let’s assume you have a books table and you are using following query to fetch all book ids from database where author’s id is 4.

SELECT id FROM `books` WHERE author_id = 4

The above query will produce following result.


And our desired output is as follows.


In order to produce the above output you can user following query.

SELECT GROUP_CONCAT(id) FROM `books` WHERE author_id = 4 GROUP BY author_id

This function concatenates multiple strings from a group into a single string.

For more information visit:

Quick Tip: How to convert a negative number to a positive number using PHP?

How To PreventDefault On ng-click In AngularJS

Here’s a handy AngularJS, trick which allows you to prevent default behavior on ng-click event.

All you need to do is pass the $event parameter to your function inside the ng-click.

<button ng-click="saveData($event)">Save</button>

And receive that parameter inside your function within your controller and preventDefault() method.

$scope.saveData = function($event) {

Must Read: How To Show Validation Errors On Submit In Angularjs?

Get Specific Columns Using Eloquent Relationships In Laravel

Here’s a handy Laravel code snippet which allows you to select specific fields using Laravel’s Eloquent relationships. Lets say we have two tables, users and posts. A user has many posts while the post belongs to single user.

Then, in my User model I can write something like,

public function post(){
        return $this->hasmany('post');

This will fetch all the columns from post table that belongs to specific post. However, if you want to summon only a specified columns you can do that using the select method.

public function post(){
        return $this->hasmany('post')->select(['title','slug']);

Quick Tip : Set friendly names for validation attributes in Laravel

Show Validation Errors On Submit In Angularjs

While working on one of my client’s project, I was required to display validation errors when the users hit the submit button. By default, AngularJS comes with $submitted form state. Its default value is false. As soon as the user hits the submit button, it becomes true.

We can use this state to make sure that error is hidden while the user has not clicked the submit button.

myForm.$submitted && myForm.username.$error.required


Note: This will work only with AngularJS 1.3 or higher

Quick Tip: Using Bootstrap Tooltip With AngularJs

5 MVC Frameworks For PHP Developers in 2016

PHP is one of the most popular open source server side scripting language in the world. The reason behind its popularity is, it is very easy to learn and understand. PHP is more flexible when it comes to writing code because of its features like, weakly typed variables, OOP is not a mandatory.

However, there is a bad side of all this flexibility, it is very easy to write bad code. And the solution to this problem is FRAMEWORK.

There are many benefits of using a framework;

  1. Organization of code is very easy as most the frameworks follow MVC pattern
  2. Most of the frameworks have active community support.
  3. Faster development
  4. Form validation
  5. Pretty URLS

In this post, we are going to go over 5 most popular frameworks in PHP community.


Created by Taylor Otwell, Laravel is one the most popular framework. It is one of the most forked project framework on github with very active community support. Laravel’s features include RESTful routing, Blade templating engine, Eloquent ORM, Socialite, Middlewares etc.




Codeigniter was released in 2006, it is a lightweight PHP framework that comes with unparalled flexibilty and extraordinary documentation. This is the best framework for beginners as it is very easy to understand and learn.



Symfony is known as one of the best option for large scale enterprise applications. Licensed under MIT license, it was created by Sensiolabs in 2005. Symfony components are used by many popular open source projects including Drupal, PHPbb and Laravel.




CakePHP was initially in 2005 and is one of the most popular framework till date. some of the features of CakePHP are code generation and scaffolding, CSRF protection, form validations, built-in ORM, Helpers, Behaviours, and Plug-ins etc.




Yii is a open source PHP framework that follows the MVC pattern. It comes bundled with tons of features that include, a powerful caching system, form validations, integrated with jQuery, and AJAX-enabled features etc.


How To Change Template Engine In Express.js

If you don’t have a view engine set in your express/node application, you need to specify file extension with each of your view files. To fix this issue you need to set a default view engine for rendering views.

You can set a template engine using following code.

app.set('view engine', 'jade')

The above code will set Jade as the default template engine. You can change jade with your own templating engine. For example, if you wish to set ejs as your default template engine, use following code.

app.set('view engine', 'ejs')

Read Also: How to use EJS in Express