array of AnagraficaSanzioni, for other array of array of AnagraficaSanzioni * * * params: * $id (int): load single rows from id * $descrizione (string): filter from like descrizione * $codice (int): filter from codice */ public static function load($id = 0, $descrizione = '', $codice = 0, $obbligo = 0) { global $con; $rows = array(); $order = " ORDER BY POSIZIONE"; $filter = " CANCELLATO = 0 "; if (!empty($id)) { $filter = " ID = :id"; } else { if (!empty($descrizione)) { $filter = " DESCRIZIONE LIKE %:descrizione% "; } if (!empty($codice)) { $filter .= ($filter != "" ? " AND " : "") . " CODICE = :codice "; } if(intval($obbligo)>0){ $filter .= ($filter != "" ? " AND " : "") . " OBBLIGO = :obbligo "; } } $filter = ($filter != "" ? " WHERE " : "") . $filter; $sql = "SELECT * FROM " . self::TABLE_NAME . $filter. $order; $query = $con->prepare($sql); if (!empty($id)) { $query->bindParam(":id", $id); } else { if (!empty($descrizione)) { $query->bindParam(":descrizione", $descrizione); } if (!empty($codice)) { $query->bindParam(":codice", $codice); } if(intval($obbligo)>0){ $query->bindParam(":obbligo", $obbligo); } } try { $query->execute(); $rows = $query->fetchAll(PDO::FETCH_ASSOC); if (!empty($id) && count($rows) > 0) { return $rows[0]; } } catch (Exception $exc) { echo $exc->getMessage(); } return $rows; } public static function getObblGruopByCodice(){ $anag_sanzioni = self::load(0, '', 0, 1); $res = array(); foreach ($anag_sanzioni as $value) { $res[$value['CODICE']][] = $value; } return $res; } public static function getGruopByCodice(){ $anag_sanzioni = self::load(); $res = array(); foreach ($anag_sanzioni as $value) { $res[$value['CODICE']][] = $value; } return $res; } }