Return JSON array through PHP Call from my index.php to function get_data($curr_date) goes from here

case "events" :
                    $curr_date = $_POST['current_date'];
                    if ( $eid = get_data($curr_date) )
                        {

                            $result = array( "success"=&gt;true,  
                            "eid"=&gt;$eid);

                            $json_output = json_encode( $result );
                            echo $json_output;
                        }
                        else
                            echo FAIL;

    break;

    enter code here


This is my function which returns the result

function get_data($curr_date)
{
    $events_list = mysql_query( "SELECT eid, display_date, word_of_the_day, word_of_the_day_meaning, thought_of_the_day, 
    crazyFact_of_the_day, joke_of_the_day FROM eventsoftheday WHERE display_date = '$curr_date' "); 
                                // get mysql result cursor
    if( mysql_num_rows( $events_list )  &gt; 0 ) // check if the query returned any records
    {
        $mysql_record = mysql_fetch_array( $events_list );    // parse mysql result cursor
        $events = array();
         $events['e_id'] = $mysql_record['eid'];
         $events['edisplay_date'] = $mysql_record['display_date'];
         $events['eword_of_the_day'] = $mysql_record['word_of_the_day'];
         $events['eword_of_the_day_meaning'] = $mysql_record['word_of_the_day_meaning'];
         $events['ethought_of_the_day'] = $mysql_record['thought_of_the_day'];
         $events['ecrazyFact_of_the_day'] = $mysql_record['crazyFact_of_the_day'];
         $events['ejoke_of_the_day'] = $mysql_record['joke_of_the_day'];

        return $events;     // return events

    }
    else
        return false;
}
Maybe it's better to return error in JSON (if FAIL constant isn't JSON yet)

echo json_encode(array('result' =&gt; false));


instead of

echo FAIL;


or return HTTP error code

header('HTTP/1.1 500 Internal Server Error');


And we can simplifify function get_data like this:

if(mysql_num_rows( $events_list )) // check if the query returned any records
{
    $mysql_record = mysql_fetch_array( $events_list );    // parse mysql result cursor
    return array(
        'e_id'                     =&gt; $mysql_record['eid'],
        'edisplay_date'            =&gt; $mysql_record['display_date'],
        'eword_of_the_day'         =&gt; $mysql_record['word_of_the_day'],
        'eword_of_the_day_meaning' =&gt; $mysql_record['word_of_the_day_meaning'],
        'ethought_of_the_day'      =&gt; $mysql_record['thought_of_the_day'],
        'ecrazyFact_of_the_day'    =&gt; $mysql_record['crazyFact_of_the_day'],
        'ejoke_of_the_day'         =&gt; $mysql_record['joke_of_the_day'],
    );
} else return false;