Wheres the flaw, simple solution.

Discussion in 'PHP' started by dkin69, Jun 3, 2007.

  1. #1
    Hey everyone, Im trying to use 2 tables at the same time, one houses comments, the other the main info for my product, now, on the comments table it has ratings, so what Im trying to do is when someone submits a rating I want to get the average for all ratings, then update my other table with the info, this is what I've written, but it doesn't seem to be working.

    mysql_connect("localhost", "user", "pass") or die(mysql_error());
    mysql_select_db("db") or die(mysql_error());
    $presult = mysql_query("SELECT AVG(rating) FROM comments where gid = '$gid'") or die ("query 1: " . mysql_error());
    $prow = mysql_fetch_array($presult) or die ("query 1: " . mysql_error());
    $result = mysql_query("UPDATE games SET rating = '$prow[rating]' WHERE id = $gid") or die(mysql_error());

    Like I said its prolly a simple solution, but its 3 am here lol.

    Thanks all

    Dylan
     
    dkin69, Jun 3, 2007 IP
  2. dkin69

    dkin69 Active Member

    Messages:
    644
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    60
    #2
    oop, resolved it myself, thanks everyone.

    Dylan
     
    dkin69, Jun 3, 2007 IP