Jump to content

Barand

Moderators
  • Posts

    24,563
  • Joined

  • Last visited

  • Days Won

    822

Everything posted by Barand

  1. A model along these lines would give greater flexibility
  2. Does this make it easier? SELECT a.ledger_code , l.ledger_name , SUM(IF(type='Dr',amount, null)) as Debits , SUM(IF(type='Cr',amount, null)) as Credits FROM acc_tbl a JOIN ledger_tbl l USING (ledger_code) GROUP BY a.ledger_code; +-------------+---------------------+--------+---------+ | ledger_code | ledger_name | Debits | Credits | +-------------+---------------------+--------+---------+ | 18 | Maintenance | 2400 | | | 30 | Annual Subscription | | 300 | | 5 | cash | 300 | 2400 | +-------------+---------------------+--------+---------+
  3. I have been looking at your data model - not a pretty sight Foreign keys in a table should match the primary keys of the referenced table. Your primary keys are INT but the foreign keys in the course table are all VARCHAR - they too should be INT. And why is the FK of tblsubject called "courseTitle"? (I couldn't see any relationship between course and subject until I saw the join your query) Date fields should be type DATE (yyyy-mm-dd). (Already changed in my version of tblstudent) Departments belong to a Faculty, so if you know the department you know the faculty. There is no need for "facultyid" in tblcourse or tblstudent. tblsession is only referenced by tblstudent. I would have thought there is a relationship between session (eg 2021/2022) and semester. Other than via the class/level there is, surprisingly, no relationship between student and course which, to me, seems the main relationship in an educational environment. Do your courses only last for a single semester? Are course and course unit part of the same entity or does a course have many units? YOUR CODE I haven't got it to run yet as changes are required. Your form has Level/Semester/Faculty put your post is expected to contain Level/Semester/Department/Faculty. For reasons known only to you, the semesterId is assigned to $sessionId. The form input should be Department instead of Faculty as faculty is redundant if you have the department. The query will change accordingly. As you only want to display data, POST should be GET.
  4. I'm pretty sure that it will be like that in Europe soon thanks to Vlad the Invader
  5. It seems mathematics and Year 7 are a poor example if everyone in Year 7 takes mathematics. In Years 10/11/12 where some students take Science, some Arts and some Commercial, how do you then know who takes which subject? (I may know my way around databases but I do not know the relationships between all the entities in your specific scenario.)
  6. There should be something that lets you know which students are taking each subject
  7. Thus far we have a list of the subjects for Year 7. Mathematics is in the list so we can click on that. What is missing now is table of students, and which subjects the students are taking, so we can find the ones taking maths
  8. I ran your query, providing some values in the WHERE clause SELECT tblcourse.Id, tblcourse.courseTitle, tbllevel.levelName, tblfaculty.facultyName, tbldepartment.departmentName, tblsemester.semesterName, tblcourse.levelId, tblcourse.semesterId, tblcourse.facultyId, tblcourse.departmentId, tblsubject.Subjects from tblcourse INNER JOIN tbllevel ON tbllevel.Id = tblcourse.levelId INNER JOIN tblsubject ON tblsubject.id = tblcourse.courseTitle INNER JOIN tblsemester ON tblsemester.Id = tblcourse.semesterId INNER JOIN tblfaculty ON tblfaculty.Id = tblcourse.facultyId INNER JOIN tbldepartment ON tbldepartment.Id = tblcourse.departmentId where tblcourse.levelId ='3' and tblcourse.semesterId ='1' and tblcourse.departmentId ='7' and tblcourse.facultyId ='9'; The output contains a single "class", ie Year 7... +----+-------------+-----------+-------------+----------------+--------------+---------+------------+-----------+--------------+------------------------------+ | Id | courseTitle | levelName | facultyName | departmentName | semesterName | levelId | semesterId | facultyId | departmentId | Subjects | +----+-------------+-----------+-------------+----------------+--------------+---------+------------+-----------+--------------+------------------------------+ | 21 | 1 | Year 7 | Adventurous | Year 7 | First Term | 3 | 1 | 9 | 7 | English Language | | 22 | 2 | Year 7 | Adventurous | Year 7 | First Term | 3 | 1 | 9 | 7 | Mathematics | | 31 | 12 | Year 7 | Adventurous | Year 7 | First Term | 3 | 1 | 9 | 7 | Yoruba | | 23 | 13 | Year 7 | Adventurous | Year 7 | First Term | 3 | 1 | 9 | 7 | French | | 24 | 15 | Year 7 | Adventurous | Year 7 | First Term | 3 | 1 | 9 | 7 | Basic Science and Technology | | 32 | 16 | Year 7 | Adventurous | Year 7 | First Term | 3 | 1 | 9 | 7 | History | | 25 | 19 | Year 7 | Adventurous | Year 7 | First Term | 3 | 1 | 9 | 7 | Business Studies | +----+-------------+-----------+-------------+----------------+--------------+---------+------------+-----------+--------------+------------------------------+ Can you explain better just what the problem is that you are having? You gave the impression that all classes were being output.
  9. Your question is all about classes. I cannot find a reference to a class entity anywhere in your tables. (I was hoping it might be in that missing table, but no) So what, in your database, constitutes a class?
  10. I can't try anything out from a picture. All it's useful for is printing and hanging on a nail in the bathroom. Good luck.
  11. Just pass the array to the function as one of the arguments $array = [5, 10, 20]; echo array_sum($array); // 35
  12. Applying the same logic to the SQL... Table:file +----+-------+------------+ | id | fname | date | +----+-------+------------+ | 1 | FileA | 2022-08-23 | | 2 | FileB | 2022-08-24 | | 3 | FileC | 2022-08-25 | +----+-------+------------+ $res = $pdo->query("SELECT fname FROM file WHERE NOW() BETWEEN date AND date + INTERVAL 1 DAY + interval 14 HOUR - INTERVAL 1 SECOND "); foreach ($res as $r) echo $r['fname'] . '<br>'; Output FileB
  13. We haven't a clue what your schema looks like. If I were doing this from the schema at the bottom of this page ( http://barringtondrew.co.uk/?page=3 ) I would use this query... mysql> SELECT classname -> , GROUP_CONCAT(DISTINCT subject ORDER BY subject SEPARATOR ', ') as subjects -> FROM class c -> JOIN pupil USING (classid) -> JOIN choice USING (pupilid) -> JOIN subject USING (subjectid) -> GROUP BY classname; +-----------+--------------------------------------------------------------------------------------+ | classname | subjects | +-----------+--------------------------------------------------------------------------------------+ | Class A | Biology, Computing, Economics, English, Geography, German, History, Maths, Physics | | Class B | Chemistry, Computing, Economics, English, Geography, German, History, Maths, Physics | | Class C | Chemistry, Computing, Economics, English, Geography, German, Maths, Physics | | Class D | Biology, Chemistry, Computing, Economics, English, German, History, Maths, Physics | | Class E | Biology, Computing, Economics, English, Geography, German, History, Maths, Physics | | Class F | Biology, Chemistry, Computing, Economics, Geography, German, History, Maths, Physics | +-----------+--------------------------------------------------------------------------------------+
  14. OK. Have you done it?
  15. I would change your method. A file dated 24/08/2022 is viewable from 2022-08-24 00:00:00 until 2022-08-25 13:59:59, so if the time now is between those times, show the file. $files = [ 'FileA' => '23/08/2022', 'FileB' => '24/08/2022', 'FileC' => '25/08/2022' ]; foreach ($files as $fname => $date) { $now = new DateTime('now'); $view = viewable($date); if ($view[0] <= $now && $now < $view[1] ) { echo $fname . '<br>'; } } function viewable($date) { $dt = DateTime::createFromFormat('d/m/Y', $date); $dt->setTime(0,0,0); $end = (clone $dt)->add(new DateInterval('P1DT14H')); return [$dt, $end]; }
  16. I assumed a course as you seem to to have some sort of assignment ...
  17. In that case, The time element of $file_date will depend on when you run the code. Which day it appears on will depend on whether you view it in the morning or afternoon
  18. First page Run query create form from results when form is submitted, second page loads Second page if (isset($_POST['job'])) { $job = "'" . join("','", $_POST['job']) . "'"; } else reload first page Run query WHERE ... IN ($job) Show output. No SESSION needed!
  19. The time element of $todays_date will depend on when you run the code $todays_date = DateTime::createFromFormat('d/m/Y', '24/08/2022'); echo $todays_date->format('Y-m-d H:i:s'); // --> 2022-08-24 14:59:27 You only need to set the default timezone once at the top (or in your php.ini file. It will be used automatically by you new DateTime() calls after that. That's why it's called the default. You can compare DateTime objects directly without formatting them if ($todays_date > $yesterday)
  20. The way to get the Dr and Cr totals is to use a group aggregation query. It seems strange that this wasn't covered in your course. Example mysql> SELECT a.ledger_code -> , type -> , SUM(amount) as total -> FROM acc_tbl a -> GROUP BY ledger_code, type; +-------------+------+-------+ | ledger_code | type | total | +-------------+------+-------+ | 18 | Dr | 2400 | | 30 | Cr | 300 | | 5 | Cr | 2400 | | 5 | Dr | 300 | +-------------+------+-------+
  21. Sorry, I gave it a try but I couldn't come up with a query that gave your expected results from the data provided. (Perhap it's because pictures of data don't load very well into my test database) I could only get +-------------+---------+---------+ | ledger_code | Debit | Credit | +-------------+---------+---------+ | 5 | 300.00 | 2400.00 | | 18 | 2400.00 | | | 30 | | 300.00 | | | 2700.00 | 2700.00 | +-------------+---------+---------+ What queries have you tried?
  22. 1 ) This line if(isset($_POST['submit'])){ belongs at the top of the second page so you only try to process the post data if any was posted. It would make more sense to check if $_POST['job'] is set. 2 ) Get rid of the SESSION code - you don't need it
  23. (float) is casting $thenumber as a float. But number_format() function definition (from the manual) is number_format( float $num, int $decimals = 0, string|null $decimal_separator = ".", string|null $thousands_separator = ",") : string therefore $thenumber is coerced to float type anyway. So, as demonstrated above, it makes no difference.
×
×
  • 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.