使用where子句插入平均值

时间:2014-11-28 18:49:17

标签: php mysql sql-update

我想从table = iis1计算column = ServiceQuality的平均值,同时将值更新为table = adminsum column = avevalue WHERE aname ='SERVICEQUALITY'

phpmyadmin中的表格如下所示:

dbname = iis; table name = adminsum;

UserID          aname              avevalue
  1        SERVICEQUALITY   (insert average value here) 
  2              USE        (insert average value here) 

我希望只要table = iis1,column = ServiceQuality的平均值发生变化,平均值就会保持更新。

这是我的编码,但似乎我错过了一些东西而且没有用。

<?php

 require_once('Connections/localhost.php');
    mysql_connect("localhost","root","");
    mysql_select_db("iis");

// Make a MySQL Connection
$conn = mysql_connect('localhost','root','');

$query = "SELECT AVG (ServiceQuality) AS average from iis1";
$result = mysql_query($query) or die(mysql_error());
$query1 = "UPDATE adminsum SET avevalue='average' WHERE aname='SERVICEQUALITY'";
$result1 = mysql_query($query) or die(mysql_error());

if (!mysql_query($query,$conn))
  {
  die('Error: ' . mysql_error());
  }
  mysql_close($conn)
?>

0 个答案:

没有答案