I'm trying to change my rating system which only used one table before but now I'm changing it to use multiple tables and I really dont no how to update or insert a new rating into the database and was wondering how to do this using my MySQL tables structure?
Ayrıca nasıl ben aşağıda listelenmiştir hangi değiştirmek istiyorum benim geçerli PHP kodu için yeni kodu uyarlayarak bu yaparsınız.
First let me explain what my tables do they hold the information when students rate there own teachers I listed what the tables will hold in the examples below to give you a better understanding of what I'm trying to do. Students are only allowed to rate there teachers once.
Ben aşağıda listelenmiştir güncelleştirilmesi gerektiğini iki MySQL tabloları sunmuştur.
Benim MySQL tablo
CREATE TABLE teachers_grades (
id INT UNSIGNED NOT NULL AUTO_INCREMENT,
grade_id INT UNSIGNED NOT NULL,
teachers_id INT UNSIGNED NOT NULL,
student_id INT UNSIGNED NOT NULL,
date_created DATETIME NOT NULL,
PRIMARY KEY (id)
);
CREATE TABLE grades (
id INT UNSIGNED NOT NULL AUTO_INCREMENT,
letter_grade VARCHAR(2) NOT NULL,
grade_points FLOAT UNSIGNED NOT NULL DEFAULT 0,
PRIMARY KEY (id)
);
Veritabanı tutmak ne olacak.
teachers_grades
id grade_id teachers_id student_id date_created
1 3 2 32 2010-01-23 04:24:51
2 1 32 3 2010-01-23 12:13:58
3 2 32 103 2010-01-23 12:24:45
grades
id letter_grade points
1 A+ 10
2 D 3
3 B 5
İşte eski PHP kodudur.
// function to insert rating
function rate(){
$text = strip_tags($_GET['rating']);
$update = "update vote set counter = counter + 1, value = value + ".$_GET['rating']."";
$result = mysql_query($update);
if(mysql_affected_rows() == 0){
$insert = "insert into vote (counter,value) values ('1','".$_GET['rating']."')";
$result = mysql_query($insert);
}
}
Eski tablo.
CREATE TABLE vote (
`counter` int(8) NOT NULL default '0',
`value` int(8) NOT NULL default '0'
);