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

 

 


Tema destacado: Entrar al Canal Oficial Telegram de elhacker.net


+  Foro de elhacker.net
|-+  Programación
| |-+  Desarrollo Web
| | |-+  PHP (Moderador: #!drvy)
| | | |-+  Ayuda PHP select dependiente PHP MySQL y Grafica
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: Ayuda PHP select dependiente PHP MySQL y Grafica  (Leído 2,017 veces)
miguel20dh

Desconectado Desconectado

Mensajes: 1


Ver Perfil
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 */
?>



« Última modificación: 6 Abril 2015, 17:43 pm por miguel20dh » En línea

Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
MySQL select con mas selects?
Bases de Datos
Azielito 6 6,141 Último mensaje 30 Septiembre 2009, 03:21 am
por ^Tifa^
[SOL] Insert into select ... mysql
Bases de Datos
Cioouw 9 11,135 Último mensaje 22 Abril 2010, 03:24 am
por Cioouw
Problema al pasar a Mysql un Select
Bases de Datos
David Vans 3 3,921 Último mensaje 1 Septiembre 2011, 04:55 am
por seba123neo
¿Eres “Facebook-dependiente”? Un nuevo estudio te ayuda a saberlo
Noticias
wolfbcn 0 799 Último mensaje 27 Diciembre 2015, 02:18 am
por wolfbcn
[Python3 + tkinter] Ayuda con combobox dependiente
Scripting
darkweb64 0 2,385 Último mensaje 8 Febrero 2017, 20:37 pm
por darkweb64
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines