SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Thread: Averaging

  1. #1
    masquerading Nick's Avatar
    Join Date
    Jun 2003
    Location
    East Coast
    Posts
    2,215
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Averaging

    I have read a couple search topics about this, but am still somewhat confused.

    I have a DB that contains writings, and I want readers to be able to rate them. They use a select menu to select a # 1-5 and then insert it into the Fiction table in the DB under clumn rating. How can I add up all results in column rating and display the avg of them?

    Here is some code I found from my searches:

    Code:
    SELECT AVG(ReviewValue) AS avgReview
         , ClubName, ClubTown
      FROM clubs
     GROUP BY ClubName, ClubTown 
     ORDER BY avgReview DESC
    Thanks!

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,220
    Mentioned
    58 Post(s)
    Tagged
    3 Thread(s)
    How can I add up all results in column rating and display the avg of them?
    Code:
    select avg(rating) from fiction
    rudy
    http://r937.com/

  3. #3
    masquerading Nick's Avatar
    Join Date
    Jun 2003
    Location
    East Coast
    Posts
    2,215
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks a lot, never knew it was so easy.

  4. #4
    masquerading Nick's Avatar
    Join Date
    Jun 2003
    Location
    East Coast
    Posts
    2,215
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Need a little help. I want to display the avg rating for each fic on the main fic selection page. Here is the code for it:

    EDIT: Also, the ratings for it is stored in the fic_comments database.

    Code:
    <? include("/home/the-barr/public_html/header.php") ?>
    
    <?php
    // Set the variables for the database access:
    $Host = "localhost";
    $User = "*****";
    $Password = "*****";
    $DBName = "thebarr_content";
    $TableName = "Fiction";
    
    $Link = mysql_connect ($Host, $User, $Password);
    
    $Query = "SELECT * from $TableName";
    
    
    $Result = mysql_db_query ($DBName, $Query, $Link); 
    
    
    // Create a table.
    print ("<TABLE WIDTH=\"60%\" BORDER=1 BORDERCOLOR=#000000 CELLSPACING=0 CELLPADDING=4 ALIGN=CENTER  class=content>\n");
    print ("<TR ALIGN=CENTER VALIGN=TOP>\n");
    print ("<TD ALIGN=CENTER VALIGN=TOP colspan=2 class=\"above\">Fan Fiction</TD>\n");
    print ("</TR>\n");
    
    // Row Who and Row Strat are switched around
    while ($Row = mysql_fetch_array ($Result)) {
     echo
    '
    	<TR ALIGN=CENTER VALIGN=TOP>
    	<TD ALIGN=left VALIGN=TOP width=50%>
    <a href="./view.php?Which='.$Row[Fic].'">'.$Row[Fic].'</a></td><td align=right width=50%>'.$Row[Name].'</TD>
     	</TR>
    ';
    
    }
    mysql_close ($Link);
    print ("</TABLE>\n");
    ?>
    
    <? include("/home/the-barr/public_html/footer.php") ?>
    How would I incorperate that code into it without messing up what I already have?


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
  •