SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast Zero G's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    63
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    dividing two columns

    Ok I am trying to setup a rating system where people can rate new articles on my site. I have setup two columns rank (the total of all the ratings) and numrates (the number of times the article has been rated. I want to have a page that displays the top five highest rated articles. Can someone please tell me what the problem is and how to fix it?

    PHP Code:

    $queryresult 
    mysql_query("SELECT id, name, (rank/numerates) AS sqlthisrank FROM atts WHERE type=$indextype ORDER BY sqlthisrank LIMIT 5" ); 
    Last edited by Zero G; Aug 8, 2003 at 13:18.

  2. #2
    SitePoint Guru asterix's Avatar
    Join Date
    Jun 2003
    Posts
    847
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    NO! You tell us what the problem is (your error message) and we'll tell you how to fix it

    Anyway, to get the top highest rated articles you don't need to divide by the number of ratings, this will give you the articles with the highest average ratings.

    Does MySQL do computed columns? Anyway you probably need to ORDER BY sqlthisrank DESC

  3. #3
    SitePoint Guru asterix's Avatar
    Join Date
    Jun 2003
    Posts
    847
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    And you say the column is called numrates but you are using numerates in the select....


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •