i have to tables result and total, the result table has two field namely student_code and mark and total table has two field namely student_code and total, the total column should contain total marks of a student. so i have written an sql statement to insert data from result table into total table by using a select statement which should take a specific student_code and his/her as a summation and then store it in the total table, but whenever i try the query either failed or just take only one student
When i use this query works but for only one student, whose student_code is 1, but i need to take all the students and they are marks as total
<?php
// copy student student_code and summation of his/her mark from result table into total table
$query = 'INSERT INTO total
(student_code, total)
SELECT student_code, SUM(mark)
FROM
result
WHERE
student_code = 1';
$sql = mysql_query($query) or (mysql_error());
?>
And when is use a student code as a variable i get nothing
<?php
// copy student student_code and summation of his/her mark from result table into total table
$query = 'INSERT INTO total
(student_code, total)
SELECT student_code, SUM(mark)
FROM
result
WHERE
student_code = "' . $student_code . '"';
$sql = mysql_query($query) or (mysql_error());
?>
Any help will be highy appreciated. thanks in advance.