false, 'error' => 'Missing facture_id')); exit; } // Hole ALLE Sections $sql = "SELECT s.rowid, s.title, s.line_order, "; $sql .= " (SELECT COUNT(*) FROM ".MAIN_DB_PREFIX."facture_lines_manager p WHERE p.parent_section = s.rowid) as product_count"; $sql .= " FROM ".MAIN_DB_PREFIX."facture_lines_manager s"; $sql .= " WHERE s.fk_facture = ".(int)$facture_id; $sql .= " AND s.line_type = 'section'"; $sql .= " ORDER BY s.line_order"; $resql = $db->query($sql); $sections = array(); while ($obj = $db->fetch_object($resql)) { $sections[] = array( 'id' => $obj->rowid, 'title' => $obj->title, 'line_order' => $obj->line_order, 'is_empty' => ($obj->product_count == 0) ); } echo json_encode(array('success' => true, 'sections' => $sections));