Your English is fine, don't worry >;o)
Here's a modified version of the PHP that should do what you want here:
<?php
$var1=$_POST['fecha1'];
$var2=$_POST['fecha2'];
/*
* IMPORTANT!
* You should validate the input dates here to prevent SQL injection attacks
*
* Also, you should change the database password, since it was posted in
plaintext on the internet
*
*/
$server = "localhost";
$username = "root";
$password = ""; // new password
$databasename = "encuestasavandaro";
$con = mysql_connect($server,$username,$password)
or die('{"error":"Error connecting to server"}');
mysql_select_db($databasename,$con);
$query = "SELECT b.id_respuesta, COUNT(b.id_respuesta) AS cnt
FROM huesped a, rompe_encuesta b
WHERE
b.id_huesped = a.id_huesped AND
b.id_aspecto = 1 AND
b.id_respuesta >= 8 AND
b.id_respuesta <= 10 AND
a.fecha BETWEEN '$var1' AND '$var2'
GROUP BY b.id_respuesta
";
$table = array();
$table['cols']=array(
array('label' => 'Type', 'type' => 'string'),
array('label' => 'Count', 'type' => 'number')
);
$rows = array();
while($r = mysql_fetch_assoc($query)){
$temp = array();
// using (int) $variable typecasts the variable as an integer, usefull when
the SQL is returning numbers as strings
switch ((int) $r['id_respuesta']) {
case 8
$type = 'word of mouth recomendation';
break;
case 9
$type = 'magazine advertisement';
break;
case 10
$type = 'roadside advertisement';
break;
default
die('{"error":"Error in SQL query: unknown \'id_respuesta\'"}');
}
$temp[] = array('v' => $type);
$temp[] = array('v' => (int) $r['cnt']);
$rows[] = array('c' => $temp);
}
$table['rows'] = $rows;
$jsonTable = json_encode($table);
echo $jsonTable;
?>
I don't have the means to test it, so there could be errors. Also, I made
a few notes in the code comments which you should read and consider
(particularly at the top of the script).
On Saturday, December 8, 2012 2:31:14 AM UTC-5, Chrystopher Medina wrote:
>
>
>
>
>>> my work is to do a survey ... and those are the answers u know i just
>>> want to show in a certain date how many people responde.... so in my sql
>>> query i obtained the results from my survey........ u know i have a
>>> question in my survey,,,, and i just want to know how many people answered
>>> to each answer......
>>>
>>
> 10 people answered the answer number one..
> 5 people answered the answer number two. and
> 2 people answered the answer number 3......
>
> I want to display this data on a graph of pie with the api google
> charts.....
>
> so u are right. i think that this is the correct
>
> Type | Count
> -----------------------------------
> word of mouth recomendation | XXXX
> magazine advertisement | YYYY
> roadside advertisement | ZZZZ
>
> so my result json was wrong ... ?
> I hope you understand me what i want--- excuse my English is very bad.....
>
--
You received this message because you are subscribed to the Google Groups
"Google Visualization API" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/google-visualization-api/-/DHp6FEvBOGkJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-visualization-api?hl=en.