elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Guía actualizada para evitar que un ransomware ataque tu empresa


  Mostrar Mensajes
Páginas: [1]
1  Programación / PHP / Ayuda PHP select dependiente PHP MySQL y Grafica en: 6 Abril 2015, 17:40 pm
Buenos días,

Vengo a pedir ayuda a los maquina del PHP. Tengo problemas a la hora de crear una lista dependiente en la cual al elegir las opciones que obtengo por unas consultas en MySQL me cree una gráfica.

Tengo la select dependiente funcionado por separado obteniendo los valores pero no consigo que la gráfica se muestre.
En cambio si hago la gráfica con una select a mi elección, me funciona perfectamente la gráfica.

Pongo el código para que le echéis un vistazo:

código de select dependiente:


Código:
<html>
<head>
<title>Graficas</title>
</head>
 
<body>
 
<?php
$servicio=$_GET['servicio'];
$fechainicio=$_GET['fechainicio'];
$fechafinal=$_GET['fechafinal'];
 
// Me conecto a la base de datos
mysql_connect("localhost","usuario","contraseña");
mysql_select_db("base");
 
if (!empty($_GET['button'])){
// en caso de que se ha presionado el boton enviar, procesar el formulario
$servicio=$_GET['servicio'];
$fechainicio=$_GET['fechainicio'];
$fechafinal=$_GET['fechafinal'];
 
/* Incluimos las clases */
include("/var/www/graficas/pChart/class/pData.class.php");
include("/var/www/graficas/pChart/class/pDraw.class.php");
include("/var/www/graficas/pChart/class/pImage.class.php");
 
/* Creamos el objeto */
$myData = new pData();
 
//conectamos
mysql_connect("localhost","usuario","contraseña");
mysql_select_db("base");
$sql2="select Fecha, Cantidad from $servicio where Fecha between '$fechainicio' and '$fechafinal'";
 
$resultado=mysql_query($sql2);
while($row = mysql_fetch_array($resultado))
{
    $Fecha = $row["Fecha"];
    $myData->addPoints($Fecha,"Fecha");
 
    $Cantidad = $row["Cantidad"];
    $myData->addPoints($Cantidad,"Cantidad");
}
 
$myData-> setSerieOnAxis("Cantidad", 0); //assigns the data to the frist axis
$myData-> setAxisName(0, "Frecuencia (Hz)"); //adds the label to the first axis
$myData-> setAxisPosition(1,AXIS_POSITION_LEFT); //moves the second axis to the far left
$myData->setAbscissa("Fecha"); //sets the time data set as the x axis label
$myPicture = new pImage(1100,300,$myData); /* Create a pChart object and associate your dataset */
$myPicture->setFontProperties(array("FontName"=>"/var/www/graficas/pChart/fonts/pf_arma_five.ttf","FontSize"=>6)); /* Choose a nice font */
$myPicture->setGraphArea(80,40,1000,200); /* Define the boundaries of the graph area */
$Settings = array("R"=>250, "G"=>250, "B"=>250, "Dash"=>1, "DashR"=>0, "DashG"=>0, "DashB"=>0);
$myPicture->drawScale(array("LabelRotation"=>320)); /* Draw the scale, keep everything automatic */
/*The combination makes a cool looking graph*/
$myPicture->drawPlotChart();
$myPicture->drawLineChart();
$myPicture->drawLegend(90,20); //adds the legend
$myPicture->autoOutput(); /* Build the PNG file and send it to the web browser */
}
else
{
?>
 
<form method="get" action="index.php">
<table width="70%" border="0" align="center">
<?php
 
print ("
<input type=\"hidden\" name=\"paisant\" value=\"$paisant\">
<input type=\"hidden\" name=\"cantonant\" value=\"$cantonant\">
 
<tr>
<td><div align=\"right\"><strong>Servicio:</strong></div></td>
 
<td><select name=\"servicio\" onchange=\"submit();\">
");
//Muestra el combobox de las provincias una vez que se haya elegido el país, no antes
if (!isset($servicio)){
print ("<option selected>Seleccione el servicio</option>");
$servicio="0";
}
$sql="SHOW FULL TABLES FROM base";
$res=mysql_query($sql);
 
while($fila=mysql_fetch_array($res)){
print("<option value=\"$fila[Tables_in_base]\"");
if ($fila[Tables_in_base] == $servicio) {
print ("selected");
}
print(">$fila[Tables_in_base]</option>\n");
}
print("</select></td></tr>");
print ("
 
<tr>
<td><div align=\"right\"><strong>Fecha de inicio:</strong></div></td>
<td><select name=\"fechainicio\" onchange=\"submit();\">
");
print ("<option selected>Seleccione la fecha de inicio</option>");
 
//Muestra el combobox de las parroquias una vez que se haya elegido el canton, no antes
if (!isset($fechainicio)){
$fechainicio="0";
}
$sqlcan="select Fecha from $servicio where Tabla='$servicio'";
$res=mysql_query($sqlcan);
 
while($fila=mysql_fetch_array($res)){
print("<option value=\"$fila[Fecha]\"");
if ($fila[Fecha] == $fechainicio) {
print ("selected");
}
print(">$fila[Fecha]</option>\n");
}
print("</select></td></tr>");
 
print("
<tr>
<td><div align=\"right\"><strong>Fecha de final:</strong></div></td>
<td><select name=\"fechafinal\">
");
 
print ("<option selected>Seleccione la fecha final</option>");
if (!isset($fechafinal)){
 
$fechafinal="0";
}
$sqlparr="select Fecha from $servicio where Tabla='$servicio'";
$resparr=mysql_query($sqlparr);
 
while($filaprov=mysql_fetch_array($resparr)){
print("<option value=\"$filaprov[Fecha]\">$filaprov[Fecha]</option>");
}
print("
</select>
</td>
</tr>
");
 
?>
 
<tr>
<td><div align="right"><input name="button" type="submit" value="Enviar"></div></td>
<td><input name="reset" type="reset" value="Borrar"></td>
</tr>
</table>
 
</form>
 
<?php
} // cierro if principal del boton enviar
 
?>
</body>
</html>


No muestra la gráfica sin error aparente. La consulta tiene el valor bien, le llegan bien los valores.



Pero si ejecuto la gráfica con una select ya predefinida funciona perfectamente. Aquí dejo el código:
Código:

<?php

/* Incluimos las clases */
include("/var/www/graficas/pChart/class/pData.class.php");
include("/var/www/graficas/pChart/class/pDraw.class.php");
include("/var/www/graficas/pChart/class/pImage.class.php");

/* Creamos el objeto */
$myData = new pData();

//conectamos
mysql_connect("localhost","usuario","contraseña");
mysql_select_db("base");
$sql2="select Fecha, Cantidad from frecuencia where Fecha between '2015-03-30 13:38:33' and '2015-03-30 13:48:34'";

$resultado=mysql_query($sql2);
while($row = mysql_fetch_array($resultado))
{
    $Fecha = $row["Fecha"];
    $myData->addPoints($Fecha,"Fecha");

    $Cantidad = $row["Cantidad"];
    $myData->addPoints($Cantidad,"Cantidad");
}

$myData-> setSerieOnAxis("Cantidad", 0); //assigns the data to the frist axis
$myData-> setAxisName(0, "Frecuencia (Hz)"); //adds the label to the first axis
$myData-> setAxisPosition(1,AXIS_POSITION_LEFT); //moves the second axis to the far left
$myData->setAbscissa("Fecha"); //sets the time data set as the x axis label
$myPicture = new pImage(1100,300,$myData); /* Create a pChart object and associate your dataset */
$myPicture->setFontProperties(array("FontName"=>"/var/www/graficas/pChart/fonts/pf_arma_five.ttf","FontSize"=>6)); /* Choose a nice font */
$myPicture->setGraphArea(80,40,1000,200); /* Define the boundaries of the graph area */
$Settings = array("R"=>250, "G"=>250, "B"=>250, "Dash"=>1, "DashR"=>0, "DashG"=>0, "DashB"=>0);
$myPicture->drawScale(array("LabelRotation"=>320)); /* Draw the scale, keep everything automatic */
/*The combination makes a cool looking graph*/
$myPicture->drawPlotChart();
$myPicture->drawLineChart();
$myPicture->drawLegend(90,20); //adds the legend
$myPicture->autoOutput(); /* Build the PNG file and send it to the web browser */
?>

Páginas: [1]
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines