query($sql); // $row = $result->fetch_assoc(); // $json_str = json_encode($row); // QRcode::png("$json_str"); include '../phpqrcode/qrlib.php'; include '../config.php'; $id = $_GET['id']; $sql = "SELECT documents.id, documents.number, type.name as doc_type, documents.description, department.name as department, company.name as company, table_of_content.number as toc_number, table_of_content.document as toc_content, city.name as city, province.name as province FROM documents LEFT JOIN type on type.id = documents.type LEFT JOIN department on department.id = documents.department LEFT JOIN company on company.id = documents.company LEFT JOIN city on city.id = documents.city LEFT JOIN province on province.id = documents.province LEFT JOIN table_of_content ON table_of_content.doc_id = documents.id WHERE documents.id=$id;"; $result = $conn->query($sql); $rows = []; $tableOfContents = []; // Array to hold Table of Contents entries while ($row = $result->fetch_assoc()) { $rows[$row['id']] = [ 'id' => $row['id'], 'number' => $row['number'], 'doc_type' => $row['doc_type'], 'description' => $row['description'], 'department' => $row['department'], 'company' => $row['company'], 'city' => $row['city'], 'province' => $row['province'] ]; // Store Table of Contents entries separately $tableOfContents[$row['id']][] = [ 'toc_number' => $row['toc_number'], 'toc_content' => $row['toc_content'] ]; } // Combine document details $combinedContent = implode(", ", array_map(function ($row) { return "ID: " . $row['id'] . ", " . "Number: " . $row['number'] . ", " . "Type: " . $row['doc_type'] . ", " . "Description: " . $row['description'] . ", " . "Department: " . $row['department'] . ", " . "Company: " . $row['company'] . ", " . "City: " . $row['city'] . ", " . "Province: " . $row['province']; }, $rows)); // Combine Table of Contents entries foreach ($tableOfContents as $docId => $tocEntries) { $combinedContent .= ", Table of Contents for Document ID $docId: " . implode(", ", array_map(function ($entry) { return $entry['toc_content'] . ': ' . $entry['toc_number']; }, $tocEntries)); } $json_str = json_encode(['document_details' => $combinedContent]); QRcode::png("$json_str");