-
Posts
24,563 -
Joined
-
Last visited
-
Days Won
822
Everything posted by Barand
-
What does var_dump($bob) output? It looks like it isn't 1 but maybe has something else in there.
-
Feedback on Data model for Cinema ticket booking system
Barand replied to webdeveloper123's topic in Application Design
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 -
That line always assigns the value "1" to $bob. When testing values for equality you need "==", therefore it should be if ($bob == 1)
-
Feedback on Data model for Cinema ticket booking system
Barand replied to webdeveloper123's topic in Application Design
Good idea!. The question is where? What is your pricing policy? -
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) ?