This should do it:
<?php
$var1 = $_POST['fecha1'];
$var2 = $_POST['fecha2'];
$server = "localhost";
$username = "root";
$password = "chrystopher";
$databasename = "encuestasavandaro";
try {
$db = new PDO("mysql:dbname=$databasename", $username, $password);
}
catch (PDOException $e) {
die("{error: {$e->getMessage()}}");
}
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$query = $db->prepare("SELECT * FROM testpower WHERE datetime > 0");
$query->execute();
$results = $query->fetchAll(PDO::FETCH_ASSOC);
$query = $db->prepare("
SELECT
b.id_respuesta,
COUNT(b.id_respuesta) AS cnt,
b.id_aspecto
FROM huesped a, rompe_encuesta b
WHERE
b.id_huesped = a.id_huesped AND
b.id_aspecto >= 1 AND
b.id_aspecto <= 4 AND
a.fecha BETWEEN :fecha1 AND :fecha2
GROUP BY b.id_respuesta, b.id_aspecto"
);
/* $parameters is an array that maps labels in the SQL to values, eg
"fecha1" maps to the value in $var1
* every bound parameter (word that begins with a ":" in the SQL) must have
a matching value in this array
* this array cannot have any extra values that are not mapped in the SQL
* PDO will throw an error if either one of these conditions is violated
*/
$parameters = array(
'fecha1' => $var1,
'fecha2' => $var2
);
try {
$query->execute($parameters);
$results = $query->fetchAll(PDO::FETCH_ASSOC);
}
catch (PDOException $e) {
die("{error: {$e->getMessage()}}");
}
$table = array();
$table['cols']=array(
array('label' => 'Type' , 'type' => 'string'),
array('label' => 'Count' , 'type' => 'number'),
// add the new column in here
);
$rows = array();
foreach ($results as $r) {
// move the contents of the old while loop into this foreach loop
}
$table['rows'] = $rows;
$jsonTable = json_encode($table);
// set up header and output json (first two prevent IE from caching queries)
header('Cache-Control: no-cache, must-revalidate');
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Content-type: application/json');
echo $jsonTable;
?>
Note that you'll have to replace the contents of the "foreach" loop with
the contents of the "while" loop in your current code as well as add the
third column to the column definitions (as I don't have a copy of your most
recent code to work from). You may also need to make adjustments to the
SQL code in case it's not quite the same as what you were using.
Importantly, though, don't change the line "a.fecha BETWEEN :fecha1 AND
:fecha2" in the SQL.
On Sunday, December 16, 2012 8:01:15 PM UTC-5, Chrystopher Medina wrote:
>
> Ok my friend i saw And i Have php5 And i can use pdo's .... could u help
> me to change mysql_query for pdo's
>
--
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/-/XIm4CxlDEroJ.
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.