Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dynamic data with jquery ajax dont work #780

Open
Rayner061 opened this issue Apr 16, 2019 · 1 comment
Open

dynamic data with jquery ajax dont work #780

Rayner061 opened this issue Apr 16, 2019 · 1 comment

Comments

@Rayner061
Copy link

        $("#diseaseselection").change(function(){
            $("#chart").empty();
            var diseaseselection = $("#diseaseselection").val();
            $.ajax({
                url: "chart.php",
                method: "POST",                   
                data: {
                    diseaseselection: diseaseselection
                },
                success: function(data) {
                    var graphdata = data;
                    console.log(graphdata)
                    Morris.Line({
                        element : 'chart',
                        data:[graphdata],
                        xkey:'totalF',
                        ykeys:[ 'totalM'],
                        labels:['Total MALE'],
                        hideHover:'auto',
                        pointStrokeColors: ['white'],
                        lineWidth:'6px',
                        parseTime: false,
                        lineColors: ['Skyblue', 'Pink'],
                    });
                }
            });
        });
@Rayner061
Copy link
Author

Rayner061 commented Apr 16, 2019

include_once('connection.php');
$diseaseselection = $_REQUEST['diseaseselection'];
if(isset($diseaseselection)){
	$result = mysqli_query($con, "SELECT disease,age,SUM(CASE WHEN gender = 'm' THEN 1 ELSE 0 END) AS `totalM`, SUM(CASE WHEN gender = 'f' THEN 1 ELSE 0 END) AS `totalF` FROM mdr where disease = '$diseaseselection' GROUP BY disease , age");
	$chart_data = '';
	while($row = mysqli_fetch_array($result))
	{
		$tabx[]=$row['totalF'];
		$taby[]=$row['totalM'];

	}
	$tableau=array_combine($tabx,$taby);
	foreach($tableau as $key=>$value){
	$string[]=array('totalF'=>$key,'totalM'=>$value);

	}
	echo json_encode($string);
}

Here is my sample PHP

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant