PHP & MySQL Update Database Problems

Imaka

New Member
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?Also how do I do this by adapting the new code to my current PHP code which I want to change which is listed below.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. I provided the two MySQL tables that should be updated which are listed below.My MySQL tables\[code\]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));\[/code\]What the database will hold.teachers_grades\[code\]id grade_id teachers_id student_id date_created1 3 2 32 2010-01-23 04:24:512 1 32 3 2010-01-23 12:13:583 2 32 103 2010-01-23 12:24:45\[/code\]grades\[code\]id letter_grade points1 A+ 102 D 33 B 5\[/code\]Here is the old PHP code.\[code\]// function to insert ratingfunction rate(){ $text = strip_tags($_GET['rating']); $update = "update vote set counter = counter + 1, value = http://stackoverflow.com/questions/2062824/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); }}\[/code\]Old table.\[code\] CREATE TABLE vote ( `counter` int(8) NOT NULL default '0', `value` int(8) NOT NULL default '0' );\[/code\]
 
Back
Top