-
Posts
24,606 -
Joined
-
Last visited
-
Days Won
831
Everything posted by Barand
-
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.
-
Just pass the array to the function as one of the arguments $array = [5, 10, 20]; echo array_sum($array); // 35
-
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
-
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 | +-----------+--------------------------------------------------------------------------------------+
-
OK. Have you done it?
-
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]; }
-
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
-
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)
-
-
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 | +-------------+------+-------+
-
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?
-
(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.
-
Push key value in multidimensionnal array in loop php
Barand replied to VitseA's topic in PHP Coding Help
Last time you told me exactly what you want there were no id elements, as in screenshot below Accordingly, I amended the code to remove them and also removed the empty children arrays (that you still keep moaning about). I posted this and asked you to verify if that was what you wanted. No reply to that request has been received. Now it appears that id elements are back in the requirements. I also notice that there is no more mention of a relationship element that was in your first post. As your requirements are changing from day to day, and I cannot get satisfactoty feedback, I am not even going to try to keep up. I guess you need to take it from here on your own. -
As with all pairs of html tags (<th>..</th>, <td>..</td> etc) the closing tag contains the "/". Yet you start the page with a closing form tag. Your next line is the opening form tag but you have placed it as far as could from the rest of the form, which doen't make for great readability. You then finish the form with another opening form tag followed by the submit button. Also there is no closing </table> tag. You want something like <form action='laminator.php' method='post'> <table> <tr> .. headings .. </tr> while( ... ) { <tr> .. table content rows .. </tr> } </table> <input type='submit'> </form>
-
Your table needs to be inside <form> ... </form> tags and you need a submit button to send the form data. In your processing page ... if ($_SERVER['REQUEST_METHOD']=='POST') { $jobs = array_map('intval', $_POST['job'] ?? [0] ); // ensure they are all numbers $sql = "SELECT ... WHERE jmmjobid IN (" . join(',', $jobs) . ")"; }