Ajax php files not works when i include in zf2

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Ajax php files not works when i include in zf2

bhuvaneshwaran
This post has NOT been accepted by the mailing list yet.
I have ajax.php file???? for select option country and state

in zf2 its not work,

but it works when my ajax,php and index.html alone in my wamp folder
<?php
    /* File : ajax.php
    */
    class AJAX {

        private $database = NULL;
        private $_query = NULL;
        private $_fields = array();
        public  $_index = NULL;
        const DB_HOST = "msphere1";
        const DB_USER = "mspheredb";
        const DB_PASSWORD = "msphere";
        const DB_NAME = "zf2tutorial";


        public function __construct(){
            $this->db_connect();                    // Initiate Database connection
            $this->process_data();
        }

        /*
         *  Connect to database
        */
        private function db_connect(){
            $this->database = mysql_connect(self::DB_HOST,self::DB_USER,self::DB_PASSWORD);
            if($this->database){
                $db =  mysql_select_db(self::DB_NAME,$this->database);
            } else {
                echo mysql_error();die;
            }
        }

        private function process_data(){
            $this->_index = ($_REQUEST['index'])?$_REQUEST['index']:NULL;
            $id = ($_REQUEST['id'])?$_REQUEST['id']:NULL;
            /*switch($this->_index){
                case 'country':
                    $this->_query = "SELECT * FROM countries";
                    $this->_fields = array('id','country_name');
                    break;
                case 'state':
                    $this->_query = "SELECT * FROM states WHERE country_id=$id";
                    $this->_fields = array('id','state_name');
                    break;

                default:
                    break;

            }*/
            switch($this->_index){
                case 'country':
                    $this->_query = "SELECT * FROM country";
                    $this->_fields = array('COUNTRY_CODE','COUNTRY_NAME');
                    break;
                case 'state':
                    $this->_query = "SELECT * FROM state WHERE STATE_COUNTRY_CODE='".$id."'";
                    $this->_fields = array('STATE_CODE','STATE_NAME');
                    break;

                default:
                    break;
            }
            $this->show_result();
        }

        public function show_result(){
            echo '<option value="">Select '.$this->_index.'</option>';
            $query = mysql_query($this->_query);
            while($result = mysql_fetch_array($query)){
                $entity_id = $result[$this->_fields[0]];
                $enity_name = $result[$this->_fields[1]];
                echo "<option value='$entity_id'>$enity_name</option>";
            }

        }
    }

    $obj = new AJAX;
?>