PHP and MySQL problems

PamAndersonFan

New Member
I'm trying to count how many times a certain article has been graded for example how many times have \[code\]users_articles_id\[/code\] \[code\]3\[/code\] been graded by my members. I'm also trying to count the points for a certain article for example \[code\]users_articles_id\[/code\] \[code\]3\[/code\] is related to the \[code\]ratings\[/code\] database by its \[code\]ratings_id\[/code\] the rating points should be a total of 13. I was wonder if I was doing this right because to me it looks all wrong? I was hoping if some one can help me fix this? And where should my code go exactly?I'm using PHP and MySQL?Here is my MySQL tables\[code\]CREATE TABLE articles_grades (id INT UNSIGNED NOT NULL AUTO_INCREMENT,ratings_id INT UNSIGNED NOT NULL,users_articles_id INT UNSIGNED NOT NULL,user_id INT UNSIGNED NOT NULL,date_created DATETIME NOT NULL,PRIMARY KEY (id));CREATE TABLE ratings (id INT UNSIGNED NOT NULL AUTO_INCREMENT,points FLOAT UNSIGNED NOT NULL DEFAULT 0,PRIMARY KEY (id));\[/code\]

Database Inputarticles_ratings\[code\]id ratings_id users_articles_id user_id date_created1 3 2 32 2010-01-13 02:22:512 1 3 3 2010-01-13 02:23:583 2 3 45 2010-01-13 02:24:45\[/code\]ratings\[code\]id points1 102 33 5\[/code\]

Here is the PHP code I'm trying to fix.\[code\]// function to retrieve ratingfunction getRating(){ $sql1 = "SELECT COUNT(*) FROM articles_ratings WHERE users_articles_id = '$page'"; $result = mysql_query($sql1); $total_ratings = mysql_fetch_array($result); $sql2 = "SELECT COUNT(*) FROM ratings JOIN ratings ON ratings.id = articles_ratings.ratings_id WHERE articles_ratings.users_articles_id = '$page'"; $result = mysql_query($sql2); $total_rating_points = mysql_fetch_array($result); if(!empty($total_rating_points) && !empty($total_ratings)){ // set the width of star for the star rating $rating = (round($total_rating_points / $total_ratings,1)) * 10; echo $rating; } else { $rating = 100; echo $rating; }}\[/code\]
 
Back
Top