25/10/2013, 10:57
|
| | Fecha de Ingreso: julio-2005
Mensajes: 73
Antigüedad: 19 años, 5 meses Puntos: 0 | |
Respuesta: Porque no Funciona? error en consulta este es el codigo con los echo para mostrar lo que sale en cada consulta. Código PHP: error_reporting(E_ERROR | E_WARNING | E_PARSE);
mysql_connect("localhost", "root", "");
mysql_select_db("dashboard");
$sql = mysql_query("SELECT site_id FROM granjas where granja_tipo=2");
while ($row = mysql_fetch_array($sql)) {
$granja[] = $row['site_id'];
$i++;
}
echo implode(",", $granja) . "<br>";
echo "Las Granjas son " . $i . "<br>";
$sql2 = mysql_query("SELECT DISTINCT (YEAR( evento )) as anio FROM partos_server");
while ($row = mysql_fetch_array($sql2)) {
$anio[] = $row['anio'];
$a++;
}
echo implode(",", $anio) . "<br>";
echo "Los Años son " . $a . "<br>";
echo "<table>";
echo "<tr>";
echo "<td>Sitio</td>";
echo "<td>prom Nacido</td>";
echo "<td>Fecha</td>";
echo "<td>Semana</td>";
echo "</tr>";
for ($j = 0; $j < $i; $j++) {
for ($b = 0; $b < $a; $b++) {
$s = 0;
unset($semana);
$sql3 = mysql_query("SELECT DISTINCT(semana) as semana FROM partos_server where YEAR(evento)=" .
$anio[$b]);
while ($row = mysql_fetch_array($sql3)) {
$semana[] = $row['semana'];
$s++;
}
echo implode(",", $semana) . " AÑO " . $anio[$b] . "<br>";
for ($t = 0; $t < $s; $t++) {
$query = @mysql_query("SELECT AVG(vivos) as promedio,site_id,year(evento)
as anio FROM `partos_server` WHERE site_id = " .
$granja[$j] . " and YEAR(evento)=" . $anio[$b] . " and semana = " . $semana[$t]) or
die("Error en Consulta.- " . mysql_error());
echo "SELECT AVG(vivos) as promedio,site_id,year(evento) as anio,semana FROM `partos_server` WHERE site_id =" .
$granja[$j] . " and YEAR(evento)=" . $anio[$b] . " and semana =" . $semana[$t] .
"<br>";
$reg = mysql_fetch_array($query, MYSQL_BOTH);
echo "<tr>";
echo "<td>" . $site = $reg['site_id'] . "</td>";
echo "<td>" . $promedio = round($reg['promedio'], 2) . "</td>";
echo "<td>" . $anio = $reg['anio'] . "</td>";
echo "<td>" . $semana = $reg['semana'] . "</td>";
$reg = mysql_fetch_array($query, MYSQL_BOTH);
echo "</tr>";
}
}
}
echo "</table>";
y esto es lo que me arroja como resultado
Código:
20,21,22,23,24,25,31
Las Granjas son 7
2012,2010,2011,2013
Los Años son 4
39,34,36,35,38,33,44,43,37,41,42,40,45,46,13,14,17,1,21,3,15,5,26,19,16,2,22,18,20,4,24,23,11,31,12,32,25,6,7,27,30,8,29,28,10,9,48,47,50,51,49,52 AÑO 2012
SELECT AVG(vivos) as promedio,site_id,year(evento) as anio,semana FROM `partos_server` WHERE site_id =20 and YEAR(evento)=2012 and semana =39
Error en Consulta.- 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 '/' at line 2
Sitio prom Nacido Fecha Semana
20 11.9 2012
el array $semana[$t] esta agarrando valores como una / , d , t ... etc. y no entiendo porque.. gracias por tu ayuda. |