Código PHP:
<?php
include 'config.php';
//$tab = $_GET['tabla'];
$tab1 = "referencia_extensa";
$tab2 = "referencia_rapida";
$sql4 = "SELECT medio, COUNT(medio) as total from ((SELECT medio FROM $tab1) UNION ALL (SELECT medio FROM $tab2)) as U
group by medio";
//$query = "SELECT * from referencia_rapida WHERE fecha BETWEEN '".$q."' AND '".$r."'";
echo sqlJson($sql4, 'totales');
function sqlJson ($sqlCons, $items){
try {
include 'config.php';
$dbh = new PDO("mysql:host=$dbhost;dbname=$dbname", $dbuser, $dbpass);
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$stmt = $dbh->query($sqlCons);
$var = $stmt->fetchAll(PDO::FETCH_OBJ);
$dbh = null;
echo '{"'.$items.'":'. json_encode($var) .'}';
} catch(PDOException $e) {
echo '{"error":{"text":'. $e->getMessage() .'}}';
}
}
?>