MySQL query with if else condition

MySql query with if-else condition:

Here’s the statement:

WHEN condition THEN statement
WHEN condition THEN statement
ELSE statement
FROM table


        WHEN q4_eps != '0' THEN q4_eps
        WHEN q3_eps != '0' THEN (q3_eps * (4 / 3))
        WHEN q2_eps != '0' THEN (q2_eps * 2)
        WHEN q1_eps != '0' THEN (q1_eps * 4)
        ELSE 0
    END) AS eps
    trading_code = 'EXIMBANK'
ORDER BY eps_year DESC

Codeigniter CSRF with AJAX

Thats the very important issue when you enable csrf protection for security reason in codeigniter framework based project then you must face some problem ajax related. So here’s the code how to resolve it :

<script type="text/javascript">


    var valrad = $("input[@name=answer]:checked").val();

    var post_data = {
        'ansid': valrad,
        '<?php echo $this->security->get_csrf_token_name(); ?>' : '<?php echo $this->security->get_csrf_hash(); ?>'

                type: "POST",
                url: "<?php echo base_url(); ?>online/checkanswer",
                data: post_data,
                success: function(msg){
                  /// do something 





How to Create Select field using Zend Framework2 Form

First I  Create Form Class name CategoryForm.php in Form directory. Source Code

// CategoryForm.php

namespace Admin\Form;

use Zend\Form\Form;

class CategoryForm extends Form {

    public function __construct($name = null) {


        $this->setAttribute('method', 'post');
        $this->setAttribute('class', 'form-horizontal');

            'type' => 'Zend\Form\Element\Select',       
            'name' => 'parentid',
            'attributes' =>  array(
                'id' => 'parentid',




In Controller i add this lines:

$form = new CategoryForm();


                                                '0' => 'Dhaka',
                                                '1' => 'Chittagong',
                                                '2' => 'Barisal',
                                                '3' => 'Khulna',

In view file i add this line :

echo $form->formSelect($form->get('parentid'));


Codeigniter pagination style with twitter bootstrap pagination

I want to style my pagination view with twitter bootstrap style and i used codeigniter php framework and twitter bootstrap. First i create controller name is front  and action is news.

public function news() {
$this->load->library('pagination');  // load pagination library
$config['base_url'] = base_url() . 'front/news';
$config['total_rows'] = $this->Fronts->totalNews(); // get no of news in my database
$config['per_page'] = 20; // no of news per page view
$config['full_tag_open'] = '';
$config['prev_link'] = '< Prev';
$config['prev_tag_open'] = '
  • '; $config['prev_tag_close'] = '
  • '; $config['next_link'] = 'Next >'; $config['next_tag_open'] = '
  • '; $config['next_tag_close'] = '
  • '; $config['cur_tag_open'] = '
  • '; $config['cur_tag_close'] = '
  • '; $config['num_tag_open'] = '
  • '; $config['num_tag_close'] = '
  • '; $config['first_link'] = FALSE; $config['last_link'] = FALSE; $this->pagination->initialize($config); $data['content'] = $this->Fronts->getAllNewsNotice(1, $config['per_page'], $this->uri->segment(3)); $this->load->view('inner/all_news', $data); }

    Then in view page write this code:

     pagination->create_links(); ?>

    After that my pagination look like twitter bootstrap pagination components.

    how to install LAMP – Apache, MySQL & PHP on Ubuntu 11.10

    LAMP : Linux Apache MySQL, PHP/Perl but in that case P : = PHP.  This is totaly open source stack. I follow this step –

    step 1. Installing Apache

    Open terminal (press Ctrl+Alt+t) and execute the command -

    sudo apt-get install apache2

    Then Open browser and type http://loacalhost. See It Works page ..


    step 2. Installing MySQL

    Execute this command in terminal (Ctrl+Alt+t) :

    sudo apt-get install mysql-server

    In installation process need set password for mysql administrative user.

    step 3. Installing PHP

    sudo apt-get install php5 libapache2-mod-php5 php5-mysql

    Then restart the apache server to load php modules. Write following command in Terminal -

    sudo /etc/init.d/apache2 restart

    After all process complete that’s ok.

    To manage MySQL database from a GUI, You may like to install phpMyAdmin – The MySQL web administration tool, a great application for managing – creating and maintaining MySQL database.

    Install phpMyAdmin on Ubuntu 11.10

    just execute the command  in your terminal -

    sudo apt-get install phpmyadmin

    on install process you need select web server such as >> apache2 and >> lighthttp.
    Enter mysql root user password and phpmyadmin password.

    Then finish….

    Make windows default boot OS alongside ubuntu OS

    When installed ubuntu 11.10 in my laptop then grub boot loader default start ubuntu os. But i need change this way thats means i want boot default start my windows 7. So i need configure my grub boot loader ….. i follow this step ………


    start terminal (ctrl+alt+t) then type

    sudo nano /etc/default/grub

    This command show this ::

    # If you change this file, run 'update-grub' afterwards to update
    # /boot/grub/grub.cfg.
    # For full documentation of the options in this file, see:

    # info -f grub -n ‘Simple configuration’

    GRUB_DISTRIBUTOR=`lsb_release -i -s 2> /dev/null || echo Debian`

    # Uncomment to enable BadRAM filtering, modify to suit your needs
    # This works with Linux (no patch required) and with any kernel that obtains
    # the memory map information from GRUB (GNU Mach, kernel of FreeBSD …)

    # Uncomment to disable graphical terminal (grub-pc only)

    # The resolution used on graphical terminal
    # note that you can use only modes which your graphic card supports via VBE
    # you can see them in real GRUB with the command `vbeinfo’

    # Uncomment if you don’t want GRUB to pass “root=UUID=xxx” parameter to Linux

    # Uncomment to disable generation of recovery mode menu entries

    # Uncomment to get a beep at grub start
    #GRUB_INIT_TUNE=”480 440 1″

    Then i change this line ::




    After change this save /etc/default/grub file
    Again goto terminal and write this command

    sudo update-grub

    Then restart my laptop and it’s working … … now perfect —