jeudi 8 mars 2018

PHP function not returning the specified value

I am working on the backend of a web application in which i have to show the list of holidays. But the problem is it throws error everytime i click on the holiday menu. working flow is like this - when i click on the holiday link, it refers to a php function api.php which calls the function given below. now that api.php takes the return value of the given function and then encode in json and then gives the output. But the function is unable to return the value to the api.php

public static function API_getYearHolidays($year = false) {  //API
    if ($year == false) {
        $year = date('Y', time());
    }
    $q = "SELECT * FROM holidays";
    $runQuery = self::DBrunQuery($q);
    $rows = self::DBfetchRows($runQuery);
    $list = array();

    if ($year == false) {
        $list = $rows;
    } else {
        foreach ($rows as $pp) {
            $h_date = $pp['date'];
            $h_year = date('Y', strtotime($h_date));
            if ($h_year == $year) {
                $list[] = $pp;
            }
        }
    }

    if (sizeof($list) > 0) {
        foreach ($list as $key => $v) {
            $list[$key]['month'] = date('F', strtotime($v['date']));
            $list[$key]['dayOfWeek'] = date('l', strtotime($v['date']));
        }
    }


    $r_error = 0;
    $return = array();
    $return['error'] = $r_error;
    $r_data['message'] = "";
    $r_data['holidays'] = $list;
    $return['data'] = $r_data;

    return $return;
}

is the problem with $r_data['message'] = ""; ??

Aucun commentaire:

Enregistrer un commentaire