SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Addict
    Join Date
    Dec 2005
    Posts
    251
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    $totalRows in a query

    Hi guys,

    I think this is mostly a syntax problem but I'm not sure. I have the following code on my page which is attempting to show the number of negative feedback a user might have. Posative feedback has a value of 1 and negative feedback 0. Therefore Total Rows Minus the Sum of Ratings gives the number of negative results.

    Code:
    echo $row_rs_rating['SUM(rate)-($totalRows_rs_rating)'];

    The query is as follows

    Code:
    SELECT SUM(rate), employer
    FROM `rate`
    WHERE employer = 'col1'
    GROUP BY employer
    Thanx again

    Tom

  2. #2
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,807
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    Try
    Code:
    SELECT SUM(rate)as rate, employer
    FROM `rate`
    WHERE employer = 'col1'
    GROUP BY employer
    along with
    PHP Code:
    echo $row_rs_rating['rate']-$totalRows_rs_rating
    See what happens
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  3. #3
    SitePoint Zealot
    Join Date
    Apr 2006
    Posts
    158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    try counting feedback when feedback =0 using count()

  4. #4
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,341
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    note: if you use a WHERE clause to restrict the employer to one value, you don't need GROUP BY

    try this:
    Code:
    SELECT SUM(rate)            as positive
         , COUNT(*) - SUM(rate) as negative 
      FROM `rate`
     WHERE employer = 'col1'
    then just display the columns called positive and negative
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  5. #5
    SitePoint Addict
    Join Date
    Dec 2005
    Posts
    251
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thats magic, thanx guys

    Tom


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
  •