query($query2); while ($row2 = $result2->fetchArray()) { $string = $row2['fullname']; $parts = explode(" ", $string); if ($parts[0] == $createdbyName){ $createEmail = $row2['email']; $createMobile = $row2['mobile']; $createdby = $row2['fullname']; } } $db2->close(); // Check if the projects.db file exists, and if not, create it $dbFile4 = $parentDirectory . '/invoices/database/invoices.db'; if (!file_exists($dbFile4)) { $db = new SQLite3($dbFile4); if (!$db) { die("Failed to create the database file."); } // Create the 'projects' table $createQuery = "CREATE TABLE IF NOT EXISTS figures ( id INTEGER PRIMARY KEY AUTOINCREMENT, item TEXT, description TEXT, subtotal TEXT )"; $db->exec($createQuery); if (!$db->exec($createQuery)) { die("Failed to create the 'projects' table."); } $db->close(); } else { $db = new SQLite3($dbFile4); if (!$db) { die("Database connection failed: " . $db->lastErrorMsg()); } } // Function to fetch and display data function displayData($db) { $query = "SELECT id, item, description, subtotal, clientname, mobile, email, address, createdby, invoicefull, projectname, createdate, clientid FROM figures"; $result = $db->query($query); $invoiceNumber = $_SESSION['invoiceNumber']; while ($row = $result->fetchArray(SQLITE3_ASSOC)) { if ($invoiceNumber == $row['invoicefull']){ $clientId = $row['clientid']; $clientname = $row['clientname']; $email = $row['email']; $mobile = $row['mobile']; $address = $row['address']; $createdby = $row['createdby']; $projectname = $row['projectname']; $createdate = $row['createdate']; $projectId = $row['id']; $item = $row['item']; $description = $row['description']; $subtotal = $row['subtotal']; $items = explode(", ", $item); $descriptions = explode(", ", $description); $subtotals = explode(",", $subtotal); for ($i = 0; $i < count($items); $i++) { $items[$i] = str_replace('*B*', ',', $items[$i]); $test = preg_replace('/\*B\*/', ',', $descriptions[$i]); echo "