I have created a query which selects UserRating and Uservotes(the number of people who voted). I want to get the average rating for all users. So this will be UserRating Divided by UserVotes. I cannot work out how I can change the SQL results into php variables which I can then calculate this with. $UR = .$rows['UserRating'].; $UV = .$rows['UserVotes'].; $Overall = $UR/$UV; PHP: This is my attempt but it doesnt work, I simply dont know the code to say $phpvariable = field-found-in-SQL-query thanks in advance.
I'm not sure how the rest of the code is structured, this would surely result in a parse error. $ur = $rows['UserRating']; $uv = $rows['UserVotes']; $overall = $ur/$uv; PHP: P.s. try var_dump()ing the result to see what it is made of!
It does result in a parse error. I was showing the code to represent what I was attempting. Basically what I was asking is how do you save a SQL result to a PHP variable.
// $connection should equal a MySQL connection resource generated via mysql_connect or similar. // $query should be your SQL query if ( !($result = mysql_query($query, $connection)) ) throw new Exception( mysql_error($connection), mysql_errno($connection) ); while ( $rows = mysql_fetch_assoc($result) ) { $overall = $rows['UserRating'] / $rows['UserVotes']; // Do something with overall here, add to an array maybe? I don't know. It's your script. } PHP: