Usamos cookies para medir audiência e melhorar sua experiência. Você pode aceitar ou recusar a qualquer momento. Veja sobre o iMasters.
Olá pessoal!
Quem pode me ajudar.?.?.?
Estou tentando pegar a média de avaliação do meu software, mas não estou conseguindo, apresenta erro de sintax.
Então, deixei o campo vazio no código abaixo.
Código MYSQL
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
mysql_select_db($database_bd_soft, $bd_soft);
$query_rs_pesquisa = "SELECT * FROM bd_pesquisa";
$rs_pesquisa = mysql_query($query_rs_pesquisa, $bd_soft) or die(mysql_error());
$row_rs_pesquisa = mysql_fetch_assoc($rs_pesquisa);
$totalRows_rs_pesquisa = mysql_num_rows($rs_pesquisa);
$somaRows_rs_pesquisa = mysql_PRECISO ACHAR A FUNÇÃO E COLOCAR AQUI_rows($rs_pesquisa);
?>
Aqui o código PHP
<?php echo ($somaRows_rs_pesquisa/$totalRows_rs_pesquisa)?>
O que estou fazendo de errado?
Tentei jogar direto no Select... mas também não deu.
Alguém consegue me dar uma luz?
Abraços,
Erilton
>
Estou tentando pegar a média de avaliação do meu software, mas não estou conseguindo, apresenta erro de sintax.
Se você quer a média, faça a consulta e resgate o valor pronto do MySQL:
mysql> select * from
valor;+----+-------+
| id | valor |
+----+-------+
| 1 | 1.000 |
| 2 | 2.000 |
| 3 | 3.000 |
| 4 | 4.000 |
| 5 | 5.000 |
| 6 | 6.000 |
| 7 | 7.000 |
| 8 | 8.000 |
| 9 | 9.000 |
+----+-------+
9 rows in set (0.00 sec)
mysql> select avg(
valor) 'media' fromvalor;+-----------+
| media |
+-----------+
| 5.0000000 |
+-----------+
1 row in set (0.00 sec)