Am urmatorul cod js:
Cod: Selectaţi tot
function fetch_select(){
val_name = $('#name').val();
$.ajax({
type: 'POST',
url: 'include/get_db.inc.php',
data: {
name: val_name,
},
success: function (response) {
document.getElementById('higtchart_medie_gen').innerHTML=response;
columnChart( JSON.parse(response));
}
});
}
function columnChart(data_v){
if(data_v.length >0){
$(function () {
$('#higtchart_medie_gen').highcharts({
chart: {
type: 'column'
},
......
Cod: Selectaţi tot
<?php
function test_name () {
$ret = [];
if(isset($_POST['name'])){
$name = $_POST['name'];
$sql = "SELECT
......
WHERE ID = $name ";
$result = $conn->query($sql);
if($result->num_rows > 0){
while($row = $result->fetch_assoc()) {
$ret [] = [$row['NAME'] . ' ' . $row['LASTN'], floatval($row['AVGG'])];
}
}
}
if(count($ret) >1) echo json_encode($ret);
else echo 'Not working';
}
?>
in ajax la url am adaugat: include/get_db.inc.php?action=test_name iar in php vreau sa adaug:
Cod: Selectaţi tot
$actions = ['nume_functie_1', 'nume_functie_2'];
if (isset($_GET['action']) && is_string($_GET['action']) && in_array($_GET['action'], $actions))) {
call_user_func($_GET['action'], $conn);
}
sau
switch($_GET['action']) {
case "nume_functie_1":
call_user_func($_GET['action'], $conn);
break;
case "nume_functie_2":
call_user_func($_GET['action'], $conn);
break;
// etc.
default:
// banez utilizatorul.
break;
}
Multumesc!