Jump to content

[SOLVED] Problems with averages (AVG)


tommyda

Recommended Posts

ERROR:You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'AND avg(quality_rating) AS quality_rating AND avg(delivery_time) AS delivery_tim' at line 1

 

I am trying to find the average of 3 columns then find the average of the averages. That sounds confusing but I dont know how to word it so heres an code, its pretty self explanitory what I am trying to do.

 

	  
$ratingq = mysql_query("SELECT avg(price_rating) AS price_rating AND avg(quality_rating) AS quality_rating AND avg(delivery_time) AS delivery_time FROM ratings WHERE s_id = '$s_id' ") 
or die(mysql_error());
$rarow = mysql_fetch_array( $ratingq );
$total = $rarow['price_rating'] + $rarow['quality_rating'] + $rarow['delivery_time'];

$num = "3";
$avg = $total / $num;
$rounded = round($avg);

echo'</a> </br>Overall Rating: '.$rounded.'/5';

 

Can anyone tell me what I am doint wrong please?

 

Link to comment
https://forums.phpfreaks.com/topic/141899-solved-problems-with-averages-avg/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.