-
Posts
24,608 -
Joined
-
Last visited
-
Days Won
831
Everything posted by Barand
-
Feedback on Data model for Cinema ticket booking system
Barand replied to webdeveloper123's topic in Application Design
Yes Do you not already have a form for the user to add movies and screenings? -
Try the jquery version (never could get my head around fetch syntax) <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script> <script type='text/javascript'> function updateStudentNames() { let selectedYear = $("#year").val() let currentSemester = $("#semester").val() $("#student").html("") // Fetch and add new options based on the selected year and current semester if (selectedYear != "" && currentSemester != "") { $.get( "class_year.php", {"year":selectedYear, "semester":currentSemester}, function(resp) { $.each(resp, function(k, v) { let name = `${v.lastname}, ${v.firstname}` let opt = $("<option>", {value:v.id, text:name}) $("#student").append(opt) }) }, "JSON" ) } } </script>
-
The student data is returned correctly in the response but the firstname and lastname are undefined by the time they get into the select. See page source... <select class="form-control rounded-0" name="student" id="student" required="required"> <option value="718">undefined undefined</option> <option value="701">undefined undefined</option> <option value="55">undefined undefined</option> <option value="43">undefined undefined</option> <option value="696">undefined undefined</option> </select> I suspect it's your use of uppercase "N" in firstName and lastName
-
Sample data would have been useful. The student_class table is telling you which students arein each class for each term. From the first two selects you know the term and class, so SELECT s.id , s.firstname , s.lastname FROM student_class sc JOIN student s ON sc.studentid = s.id WHERE sc.semesterid = ? AND sc.classid = ?
-
Stick with your first code block. Instead of returning "true" on success return $email['fk_UserTypes_Id']. Then you just need to check the login return value to decide the next page.
-
What errors does it show? It would be helpful for us to know.
-
Graph showing comparative analysis of students class performance.
Barand replied to Olumide's topic in PHP Coding Help
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; -
Graph showing comparative analysis of students class performance.
Barand replied to Olumide's topic in PHP Coding Help
Divide total by the number of scores for the subject. Your query is calculating average for each student's scores, not for the class -
Graph showing comparative analysis of students class performance.
Barand replied to Olumide's topic in PHP Coding Help
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. -
Graph showing comparative analysis of students class performance.
Barand replied to Olumide's topic in PHP Coding Help
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?" -
PHP Notice: Undefined index: data in.. repeated log errors
Barand replied to myphp's topic in PHP Coding Help
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>'; -
Ghoti? Is that pronounced "fish"
-
When defining an array, key/value associations use fat arrows, not equals. $test[] = array("name" => "Steve", "qty" => "1"); ^^ ^^
-
Re-structuring your array would simplify. $test = ['Steve' => 1]; $search = 'Joe'; if (isset($test[$search])) { $test[$search]++; } else $test[$search] = 1;
-
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)
-
Here's my solution using your (terrible) data structure... giving If you want those beginning with 'z', then giving
-
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>';
-
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 )
-
ksort($words) ?
-
Feedback on Data model for Cinema ticket booking system
Barand replied to webdeveloper123's topic in Application Design
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. -
Are you sure "index.php" is in your root folder?
-
Feedback on Data model for Cinema ticket booking system
Barand replied to webdeveloper123's topic in Application Design
@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 -
Feedback on Data model for Cinema ticket booking system
Barand replied to webdeveloper123's topic in Application Design