Jump to content

Barand

Moderators
  • Posts

    24,602
  • Joined

  • Last visited

  • Days Won

    830

Everything posted by Barand

  1. What errors does it show? It would be helpful for us to know.
  2. This query uses WINDOW function to get the class averages for each subject. (I am using MariaDB 11.1 but MySql 8 also has them). If you don't have then then us a subquery to get the class averages and join to that. SELECT studentid , subjectname , student_score , ROUND(AVG(student_score) OVER (PARTITION BY subjectname)) as mean FROM ( SELECT sc.semesterid, sc.classid, sc.studentid, s.subjectname, SUM(r.score) AS student_score 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 = 10 AND sc.classid = 1 GROUP BY subjectname, studentid ) totals ORDER BY studentid, subjectname;
  3. Divide total by the number of scores for the subject. Your query is calculating average for each student's scores, not for the class
  4. That is not the class average, it's the average score by the student in each of the four term tests The class average would be the total scores attained by all students in the class for the subject divided by the number of students.
  5. Let's look at the mathematics scores in your example images above. SUM(score) for the term 68 (ie 5+8+10+45) and those give a mean value of (5+8+10+45)/4 = 17. Those correctly reflect the values shown by your chart. So the questions is "what average are you wanting to show if that is wrong?"
  6. The error is probably in the code that creates your $ipdetails array. Have you checked the contents of the array? echo '<pre>' . print_r($ipdetails, 1) . '</pre>';
  7. Ghoti? Is that pronounced "fish"
  8. When defining an array, key/value associations use fat arrows, not equals. $test[] = array("name" => "Steve", "qty" => "1"); ^^ ^^
  9. Re-structuring your array would simplify. $test = ['Steve' => 1]; $search = 'Joe'; if (isset($test[$search])) { $test[$search]++; } else $test[$search] = 1;
  10. PS I am in complete agreement with @kicken - you need to restructure your tables +---------------+ | link | +---------------+ | id (PK) |-----+ | url | | +---------------+ +---------------+ | | term | | +---------------+ | | id (PK) | +-----<| link_id (FK) | | term | +---------------+ So that your data looks like this... TABLE: link TABLE: term +-----+-------------------+ +-----+---------+---------------------+ | id | url | | id | link_id | term | +-----+-------------------+ +-----+---------+---------------------+ | 1 | page1.php | | 1 | 1 | Zeitgeist | | 2 | page2.php | | 2 | 1 | conspiracy theories | +-----+-------------------+ | 3 | 1 | 9/11 | | 4 | 1 | 9 11 | | 5 | 2 | zine | | 6 | 2 | magazine | | 7 | 2 | online | | 8 | 2 | newspaper | | 9 | 2 | press | | 10 | 2 | alternative | | 11 | 2 | coldtype | | 12 | 2 | world news | +-----+---------+---------------------+ Then all you need is a couple of simple queries. (My reply to your previous topic assumed were using a correctly normalized design as above)
  11. Here's my solution using your (terrible) data structure... giving If you want those beginning with 'z', then giving
  12. Once again we have no idea what the data you are processing looks like. Post the output from this code... echo '<pre>' . var_export($data, 1) . '</pre>';
  13. Assuming your data looks something like this table... ### CREATE SOME TEST DATA FIRST $pdo->exec("CREATE TEMPORARY TABLE links (terms varchar(20))"); $pdo->exec("INSERT INTO links (terms) VALUES ('rhubarb'), ('dog'), ('ferret'), ('zucchini'), ('daffodil'), ('yeti'), ('misery'), ('ferret')"); then $stmt = $pdo->query("SELECT DISTINCT terms FROM links ORDER BY terms "); $results = array_column($stmt->fetchAll(), 'terms'); echo '<pre>' . print_r($results, 1) . '</pre>'; giving Array ( [0] => daffodil [1] => dog [2] => ferret [3] => misery [4] => rhubarb [5] => yeti [6] => zucchini )
  14. ksort($words) ?
  15. Screen.rows, screen.columns, screen.capacity look like derived values to me - you can get that info from the seats for each screen. booking.ticket_date is no longer required - duplicates the screening.screen_on value. However, you need to consider the payment process. What if a user books seats and their payment is subsequntly declined? You would need to know who made the booking. Perhaps make the booking.ticket date an automatic timestamp and, on booking, set a status "payment pending". Set status to "paid" on successful payment. Periodically remove pending payments older than X minutes to release the seats for sale again.
  16. Are you sure "index.php" is in your root folder?
  17. @gizmola With my model you would need to bring the ticket date into the equation SELECT s.id, s.row, s.seat_no FROM seat s LEFT JOIN booking b ON b.seat_id = s.id AND b.screening_id = 35 AND B.ticket_date = '2024-01-03' -- also required WHERE s.screen_id = 1 AND b.id IS NULL; As it is, a screening record states that the movie will be screened at time T each day between X and Y. On reflection, although requiring more rows, it would be better to have a screening record for every individual screening, giving... then your query would work as it is. Alternatively, to get vacant seats for a screening (and only requiring the screening id as input - if the screening id is known then the screen id is also known) you could SELECT s.id, s.row, s.seat_no FROM screening sg JOIN seat s ON sg.screen_id = s.screen_id LEFT JOIN booking b ON b.screening_id = sg.id AND b.seat_id = s.id WHERE sg.id = 35 AND b.id IS NULL
  18. What format is $_POST['date']? When binding the query params, $date is a string value - you specified "d" (double) and not "s" (string). Please use the code button "<>" when posting code in future.
  19. By default, div widths are 100% [edit]... PS you could add some css of your own in the style section of the head. <!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>Bootstrap demo</title> <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-T3c6CoIi6uLrA9TneNEoa7RxnatzjcDSCmG1MXxSR1GAsXEV/Dwwykc2MPK8M2HN" crossorigin="anonymous"> </head> <style type='text/css'> .alert-success { width: 25%; text-align: center; } </style> <body> <h1>Hello, world!</h1> <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-C6RzsynM9kWDrMNeT87bh95OGNyZPhcTNXj1NW7RuBCsyN/o0jlpcV8Qyq46cDfL" crossorigin="anonymous"></script> <?php echo "<div class='alert alert-success' role='alert'>this is my_message</div>"; ?> </body> </html>
  20. Have you tried it?
  21. The above code is invalid php syntax. That's why there is no output. Try <?php echo "<div style='color: green;'>my_message</div>"; echo "my error"; echo 'my error 2'; ?>
  22. P.S. You should be using a prepared statement to avoid SQL injection $stmt = $conn->prepare("INSERT INTO user (name, email, phone) VALUES (?, ?, ?); $stmt->bind_param('sss', $name, $email, $phone); $stmt->execute(); And, to make life easier for yourself, switch to PDO instead of mysqli.
  23. Try changing $sql= "INSERT INTO 'user' ('name', 'email', 'phone') VALUES ('$name', '$email', '$phone')"; to $sql= "INSERT INTO `user` (`name`, `email`, `phone`) VALUES ('$name', '$email', '$phone')"; Backticks, not single quotes (but unnecessary they are not reserved words)
  24. I hope I am wrong on this, but my theory is that if we total all the values in your query output "Total" column to get an overall total then that should equal the total of all billing.gross_amount values for sales_office 801. mysql> SELECT format(sum(x.Total),0) as grandTotal -> FROM ( -> SELECT sum(a.gross_amount) AS Total, b.DistributionChannelDesp AS Department, c.branchName AS Branch, -> d.grpName AS DepartmentGroup, e.equiSubName AS Equipment, g.mgName AS Material -> FROM sbms.billing AS a -> INNER JOIN sbms.department_code AS b ON b.DChannel = a.dchannel -> INNER JOIN sbms.branch AS c ON c.branchcode = a.sales_office -> INNER JOIN sbms.dept_group AS d ON d.grpID = b.grpID -> INNER JOIN sbms.equipmentsubcategory AS e ON e.eqipSubCode = a.division -> INNER JOIN sbms.materialsubgroup AS f ON f.mgsubNumber = a.material -> INNER JOIN sbms.materialgroup AS g ON g.mgID = f.mgID -> WHERE a.sales_office='801' -> GROUP BY b.DistributionChannelDesp, d.grpID, e.equiSubName, g.mgID -> ) x ; +---------------+ | grandTotal | +---------------+ | 1,998,441,259 | +---------------+ 1 row in set (1.47 sec) mysql> SELECT format(sum(a.gross_amount),0) AS Total_801 -> FROM billing a -> WHERE sales_office='801'; +---------------+ | Total_801 | +---------------+ | 6,195,206,276 | +---------------+ 1 row in set (0.74 sec) As you can see there is a minor discrepancy of around 4 billion. (4,196,765,017 to be precise).
×
×
  • 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.