Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP and MySQL problems
    text
    copied!<p>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. </p> <p>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. </p> <p>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?</p> <p>I'm using PHP and MySQL?</p> <p>Here is my MySQL tables</p> <pre><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></pre> <p><br /> <br /></p> <p>Database Input</p> <p><b>articles_ratings</b></p> <pre><code>id ratings_id users_articles_id user_id date_created 1 3 2 32 2010-01-13 02:22:51 2 1 3 3 2010-01-13 02:23:58 3 2 3 45 2010-01-13 02:24:45 </code></pre> <p><b>ratings</b></p> <pre><code>id points 1 10 2 3 3 5 </code></pre> <p><br /> <br /></p> <p>Here is the PHP code I'm trying to fix.</p> <pre><code>// function to retrieve rating function 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) &amp;&amp; !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></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload