Jump to content

Barand

Moderators
  • Posts

    24,563
  • Joined

  • Last visited

  • Days Won

    822

Everything posted by Barand

  1. What does var_dump($bob) output? It looks like it isn't 1 but maybe has something else in there.
  2. The price is not a property of a movie entity, it is dependent on the year (or date period depending on whether the change date is alway jan 1st or not) Have a price table +-------------------+ | price | --------------------+ | year YEAR (PK) | | price DECIMAL(6,2)| +-------------------+ But if it changes during the year +-------------------+ | price | --------------------+ | id INT (PK) | | from DATE | | until DATE | | price DECIMAL(6,2)| +-------------------+ Then join to the price table to get the price SELECT price FROM screening s JOIN price p ON s.screen_on BETWEEN p.from AND p.until or SELECT price FROM screening s JOIN price p ON YEAR(s.screen_on) = p.year depending on the change date
  3. That line always assigns the value "1" to $bob. When testing values for equality you need "==", therefore it should be if ($bob == 1)
  4. Good idea!. The question is where? What is your pricing policy?
  5. Yes Do you not already have a form for the user to add movies and screenings?
  6. 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>
  7. 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
  8. Why is the required semesterid hard-coded and not passed in the fetch request? Do you have data for semesterid = 1 and the selected year?
  9. Sorry, missed the bit about the second select being year and not class. Try SELECT s.id , s.firstname , s.lastname , c.classname FROM class c JOIN student_class sc ON sc.classid = c.id AND semesterid = ? JOIN student s ON sc.studentid = s.id WHERE c.year = ? ORDER BY lastname;
  10. 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 = ?
  11. 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.
  12. What errors does it show? It would be helpful for us to know.
  13. 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;
  14. Divide total by the number of scores for the subject. Your query is calculating average for each student's scores, not for the class
  15. 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.
  16. 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?"
  17. 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>';
  18. Ghoti? Is that pronounced "fish"
  19. When defining an array, key/value associations use fat arrows, not equals. $test[] = array("name" => "Steve", "qty" => "1"); ^^ ^^
  20. Re-structuring your array would simplify. $test = ['Steve' => 1]; $search = 'Joe'; if (isset($test[$search])) { $test[$search]++; } else $test[$search] = 1;
  21. 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)
  22. Here's my solution using your (terrible) data structure... giving If you want those beginning with 'z', then giving
  23. 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>';
  24. 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 )
×
×
  • 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.