Jump to content

Olumide

Members
  • Posts

    133
  • Joined

  • Last visited

  • Days Won

    3

Everything posted by Olumide

  1. I want to generate a bar chart that will show the score of students in each subject and the mean. I am a bit confused in the mean aspect as what I am getting is far below my expected result. I would appreciate if more light can be shed on how to go about this getting the mean. I have the php code below and the output of the graph. $res = $pdo->prepare("SELECT s.subjectname, SUM(r.score) AS student_score, SUM(r.score) / COUNT(r.score) AS mean FROM result r JOIN student_class sc ON r.studentclassid = sc.id JOIN course c ON r.courseid = c.id JOIN subject s ON c.subjectid = s.id JOIN semester sm ON sc.semesterid = sm.id WHERE sm.id = ? AND sc.classid = ? AND sc.studentid = ? AND sm.semestername+0 <= 3 GROUP BY s.subjectname ORDER BY s.subjectname"); $res->execute([$semester, $clid, $student]); $data = $res->fetchAll(PDO::FETCH_ASSOC); // Prepare data for JSON response $response = [ 'labels' => [], 'scores' => [], 'classAvg' => [] ]; foreach ($data as $row) { $response['labels'][] = $row['subjectname']; $response['scores'][] = (int) $row['student_score']; $response['classAvg'][] = round((float) $row['mean'], 2); } // Return data in JSON format header('Content-Type: application/json'); echo json_encode($response); exit;
  2. Olumide

    Greetings!

    I assumed symfony does not support MySQL database.
  3. Olumide

    Greetings!

    Programming is good and funs but I am always baffled because there are many programming languages and more are still emerging. During my university days, I was only thought the basic QBasic, Fortran, MATLAB, C++, Assembly Language, Java, and Internet of a thing.
  4. Olumide

    Greetings!

    Please can you give me any link to learn the symfony in an easier mode as a beginner?
  5. A common approach is to use screen recording software to capture the animation and then convert it to the desired format.
  6. The problem might be with the placement of the array_unique function. Try this modification: $stmt = $pdo->prepare("SELECT DISTINCT terms FROM links WHERE terms LIKE ? GROUP BY terms"); $stmt->execute(array("$alpha%")); $data = $stmt->fetchAll(); foreach ($data as $result_tag) { $one = implode(', ', $result_tag) . ""; $two = strtok($one, ',') . "<br>"; $three = strtolower($two); $words = explode(" ", $three); $unique_words = array_unique($words); $string = implode(" ", $unique_words); echo $string; } exit();
  7. I use a different approach by using the `wp_get_referer()` function to check the referring page. If the referring page is not the 'order-received' page, then it will proceed with the redirection. ```php add_action('woocommerce_thankyou', 'upsell_redirect'); function upsell_redirect($order_id) { // Get the referring page $referer = wp_get_referer(); // Check if the referring page is not the 'order-received' page if ($referer && false === strpos($referer, 'order-received')) { WC()->session->set('original_order_id', $order_id); $upsell_page_url = home_url('/upsell-1'); wp_redirect($upsell_page_url); exit; } } ```
  8. Instead of relying on the is_wc_endpoint_url function, you can use the is_order_received_page function to check if you are on the order received page.
  9. I adjusted it this way add_action('woocommerce_thankyou', 'upsell_redirect'); function upsell_redirect($order_id) { // Check if not on the 'order-received' page if (!is_order_received_page()) { WC()->session->set('original_order_id', $order_id); $upsell_page_url = home_url('/upsell-1'); wp_redirect($upsell_page_url); exit; } }
  10. Try it this way add_action('woocommerce_thankyou', 'upsell_redirect'); function upsell_redirect($order_id) { // Check if not on the 'order-received' page if (!is_wc_endpoint_url('order-received')) { WC()->session->set('original_order_id', $order_id); $upsell_page_url = home_url('/upsell-1'); wp_redirect($upsell_page_url); exit; } }
  11. You can try checking if the current request is for the 'order-received' endpoint using the is_wc_endpoint_url function with the specific order ID. Here's an updated version of your code: add_action('woocommerce_thankyou', 'upsell_redirect'); function upsell_redirect($order_id) { // Check if the current request is for the 'order-received' endpoint with the specific order ID if (is_wc_endpoint_url('order-received') && get_query_var('order-received') == $order_id) { return; } WC()->session->set('original_order_id', $order_id); $upsell_page_url = home_url('/upsell-1'); wp_redirect($upsell_page_url); exit; }
  12. I have an invoice table whereby if payment is made or recorded, it should update the table by setting the tendered_amount, if the tendered_amount is greater than the total_amount, the result/value should be store in change_balance (e.g. 500 - 300 = 200) and if the tendered_amount is lower than the total_amount, that is debts because the amount expected is not equal to the tendered amount, but if the tendered amount is equal to the total amount, the user has fully paid and the status should change to 'paid', also, if the tendered amount is greater than the total amount, the status will also change to paid because he overpaid. // Calculate change_balance, debts, and update status $change_balance = max(0, $amount_paid - $invoice_data['total_amount']); $debts = max(0, $invoice_data['total_amount'] - $amount_paid); $status = ($debts == 0) ? 'paid' : 'unpaid'; // Update the tendered_amount, change_balance, debts, and status columns $update_query = "UPDATE `invoices` SET `tendered_amount` = '{$amount_paid}', `change_balance` = '{$change_balance}', `debts` = '{$debts}', `status` = '{$status}' WHERE `invoice_code` = '{$invoice_code}'";
  13. Try this .curved-bottom { position: absolute; bottom: 0; left: 0; width: 100%; height: 200px; /* Adjust the height of the curved bottom */ background-color: #000000; /* Set the background color */ clip-path: ellipse(100% 60% at 50% 40%); }
  14. This should help. $category = $_POST['category']; $folder1 = "uploads/categoryA/"; $folder2 = "uploads/categoryB/"; $folder3 = "uploads/categoryC/"; switch ($category) { case 'categoryA': $uploadFolder = $folder1; break; case 'categoryB': $uploadFolder = $folder2; break; case 'categoryC': $uploadFolder = $folder3; break; default: die("Invalid category"); } // it check if the folder exists, if not, it create it if (!file_exists($uploadFolder)) { mkdir($uploadFolder, 0777, true); } $uploadedFile = $_FILES['file']['tmp_name']; $destination = $uploadFolder . $_FILES['file']['name']; if (move_uploaded_file($uploadedFile, $destination)) { echo "File successfully uploaded to $uploadFolder"; } else { echo "Error uploading file"; }
  15. There is a slight error in the second foreach loop where you check for extra SKUs. You are comparing the received count with the expected count, but you should be checking if the received count is greater than the expected count. Try replacing the second foreach statement with this: foreach ($received_counts as $sku => $received_count) { if (!isset($expected_counts[$sku])) { $extra = array_merge($extra, array_fill(0, $received_count, $sku)); } elseif ($received_count > $expected_counts[$sku]) { $extra = array_merge($extra, array_fill(0, $received_count - $expected_counts[$sku], $sku)); } }
  16. Can you try something like: # Redirect /shop/{cat}/{sub-cat}/{product}/ to /shop/{cat}/{product}/ RewriteRule ^shop/([^/]+)/([^/]+)/([^/]+)/$ /shop/$1/$3/ [R=301,L]
  17. It seems like the variable $siteOwnersEmail is used, but its value is not defined in your provided code. You need to set the email address where you want to receive the form submissions. Add the following line at the beginning of your script, before the if($_POST) line: $siteOwnersEmail = '[email protected]'; Replace '[email protected]' with the actual email address where you want to receive the form submissions. Additionally, there's a small error in your code. You're using $Name in your message concatenation, but the variable is actually $name (lowercase). Update the line to: $message .= "Email from: " . $name . "<br />"; After making these changes, your script should work better.
  18. The provided code (connection.txt file) appears to be error-free. However, the success of the code depends on the context and how the functions are used in the rest of your script. NB: It's crucial to keep sensitive information like database login credentials secure.
  19. Please note the modification assumes you have a secure/SecurePDO.php file that contains your PDO connection and appropriate functions. Make sure to adjust this based on your actual implementation.
  20. Here's the modified version of your code for the second attachment which I was unable to download earlier. <?php // Banking Version 2.0.0 31-03-2023 Desmond O'Toole. include("secure/SecureFunctionsBank.php"); include("../secure/SecurePDO.php"); error_reporting(E_ALL); ini_set('display_errors', '1'); // Start the session session_start(); $page = "Bank Login"; Session_Init(); if (!isset($_SESSION["Pk"])) { header('Location: index.php'); exit; } $Pk = $_SESSION["Pk"]; if (KeyCheckX($Pk) == 0) { header('Location: index.php'); exit; } $EndTime = KeyTestX($Pk, 0); $_SESSION["current_page"] = $page; $qBalance = GetBalance(); $Date = $qBalance['EntryDate']; $Value = $qBalance['BalanceValue']; $stamp = strtotime($Date); $StartDate = date('D d-M-Y', $stamp); $stamp = $stamp + (WEEKS * 6) + (DAYS * 1); $EndDataDate = date('D d-M-Y', $stamp); $curValue = $Value; ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html lang="en"> <head> <title>Bank Home 2</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <meta http-equiv="imagetoolbar" content="no"> <meta http-equiv="refresh" content="60"> <link rel="stylesheet" href="stylesheets/Library.css" type="text/css"> <link rel="stylesheet" href="stylesheets/LibraryMenu.css" type="text/css"> </head> <body> <div id="PageTitle"> <img src="images/LibraryBanner.jpg" alt=""> </div> <?php include('SideMenu.php'); ?> <div id="PageContent"> <form action="menu.php" method="post"> <span style="color:blue;"><b>Est: 18-July-2015</b></span> <h4><?= "Displayed data up to " . $EndDataDate ?><?= "<br>Log on ends on " . $EndTime ?> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href="DeleteOldData.php"><span style="color:blue">Clear old data</span></a> <br> </h4> <div style="width:850px;padding:0px;float:left;"> <!-- ... Rest of your HTML code ... --> <?php $stmt = GetAllData($Date); while ($row = $stmt->fetch()) { // ... Rest of your loop code ... } ?> <!-- ... Rest of your HTML code ... --> </div> <div style="width:670px;height:50px;padding:0px;float:left;"> <input class="MyButton" type="submit" name="direction" value="Main Menu"> <br> </div> </form> </div> </body> </html>
  21. Your code seems to be a mix of old and new PHP practices. The main issue you're facing could be due to the deprecated `mysql` functions. You should switch to using `PDO` consistently throughout your code, as you've started doing in some places. Here's an updated version of your code using `PDO`: <?php define('OTHER', 1); define('SHOPS', 10); define('ONLINE', 11); define('CASH', 12); define('EBAY', 15); define('ARGOS', 16); // ... (other constants and functions) function GetBalance() { $pdo = connectDB(); $stmt = $pdo->query("SELECT * FROM Bank_config"); $row = $stmt->fetch(); return $row; } function GetAllData($StartDate) { $pdo = connectDB(); $sqlAllData = "SELECT * FROM Bank_Data WHERE EntryDate > :StartDate AND EntryDate <= DATE_ADD(:StartDate, INTERVAL 6 WEEK) ORDER BY EntryDate ASC, Output"; if ($_SESSION['CounterValue'] == 'Total') { $sqlAllData = "SELECT * FROM Bank_Data ORDER BY EntryDate ASC, Output"; } if ($_SESSION['CounterValue'] == 'Database') { $sqlAllData = "SELECT * FROM Bank_Data ORDER BY EntryDate ASC, Output"; } $stmt = $pdo->prepare($sqlAllData); $stmt->execute(['StartDate' => $StartDate]); return $stmt; } // ... (other functions) function DeleteOldData() { $pdo = connectDB(); $Date = time(); $Month = date('m', $Date); $Year = date('Y', $Date); $Month -= 1; if ($Month == 0) { $Month = 12; $Year -= 1; } $Date = $Year . "-" . $Month . "-01"; $sqlOldData = "DELETE FROM `Bank_Data` WHERE EntryDate < :Date"; $stmt = $pdo->prepare($sqlOldData); $stmt->execute(['Date' => $Date]); } ?> Please note that you should replace `connectDB()` with your actual database connection function. This code assumes that `connectDB()` returns a valid PDO connection. Update other parts of your code similarly to use PDO consistently.
  22. If you're encountering issues with the code under PHP 8, there might be some compatibility issues. However, let's check a few things: 1. **Check for PDO Extension:** Ensure that the PDO extension is enabled in your PHP configuration. You can do this by checking your `php.ini` file or by creating a PHP file with `phpinfo();` and checking if PDO is listed. 2. **Error Handling:** Check if there are any error messages that might give you more information about what's going wrong. You can add error handling to your PDO code: ```php try { $pdo = connectDB(); $stmt = $pdo->query("SELECT * FROM Bank_config"); $row = $stmt->fetch(); return $row; } catch (PDOException $e) { echo "Error: " . $e->getMessage(); } ``` This will print any errors that occur during the execution of the query. 3. **Function Implementation:** Ensure that the `connectDB()` function is correctly implemented and returns a PDO instance. If there's an issue with this function, it might affect the query execution. 4. **Table and Column Names:** Make sure that the table name (`Bank_config`) and column names in your query match the actual structure of your database. In PHP 8, there might be stricter adherence to correct syntax. 5. **PHP Short Tags:** Ensure that your PHP files are using the full `<?php` tag rather than short tags (`<?`). Although this is less likely to be an issue, it's a good practice for compatibility. 6. **PHP Version Mismatch:** Double-check that your web server is using PHP 8. Sometimes, there might be multiple PHP versions installed, and the web server could be configured to use a different version. If you still face issues, please provide any error messages you receive, and I'll do my best to assist you further.
  23. Do you want to customize the include path for PHP on a shared hosting environment? You can achieve this by modifying the .htaccess file. Here's an example: php_value include_path ".:/your/custom/path" Replace /your/custom/path with the desired path. Keep in mind that not all shared hosting environments allow customizing certain PHP configurations due to security restrictions.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.