Search
 
SCRIPT & CODE EXAMPLE
 

PHP

jquery get data from php

You can read about ajax in javascript and make an ajax request that gets the json object from PHP then process that in your javascript:

Example (with some improvement to your PHP code)

PHP
  
$chart6 = $controller->runQuery("SELECT DATE(pay_date) `DATE`, SUM(amount) daily_amount, DATE_FORMAT(pay_date,'%a') DAYNAME FROM tbl_paid WHERE DATE(pay_date) BETWEEN DATE(:today) - INTERVAL 1 WEEK AND DATE(:today) GROUP BY DATE(pay_date);"); 
$chart6->execute(array(":today"=>$today));
$labels = array();
$series = array()
while($fetch = $stmt->fetch(PDO::FETCH_ASSOC)) {
  $labels[] = $fetch['DAYNAME'];
  $series0[] = $fetch['daily_amount'];
}
$series[] = $series0;

// add the labels and series to an array, then convert that to json
$data = array('labels' => $labels, 'series' => $series);
echo json_encode($data);

JS:

// Make an Ajax request, here I am using jQuery $.getJSON  but you can use $.get or $.post if you need to have it as a post request, or even $.ajax

$.getJSON('https://example.com/database_fetch_page.php', function(data) {
  new Chartist.Line('#headline-chart', data, options);
});
Comment

PREVIOUS NEXT
Code Example
Php :: sage theme 
Php :: test_input php 
Php :: laravel multiple images upload 
Php :: php is closure 
Php :: Spatie vendor publish 
Php :: laraval routing 
Php :: laravel eloquent with 
Php :: PHPDoc @method 
Php :: how to make primary key and foreign key in phpmyadmin 
Php :: laravel echo 
Php :: how to hide submenu admin wordpress 
Php :: php move index of a value to first position in array 
Php :: php array in variable 
Php :: laravel run command 
Php :: In PackageManifest.phpIn PackageManifest.php line 122: Undefined index: name line 122: Undefined index: name 
Php :: php carbon 
Php :: laravel relations find 
Php :: convert html to pdf php 
Php :: php "?int" 
Php :: laravel get data from database by id 
Php :: blocked token vs expired token 
Php :: upload image in laravel 
Php :: laravel eloquent batch insert 
Php :: php system info script 
Php :: laravel dynamically add remove table row 
Php :: Wampserver does not use, modify or require the PATH environment variable. 
Php :: codeigniter admin panel with crud generator - 
Php :: php header accept post request from same domain 
Php :: mysql php update sum same table 
Php :: form data to php Class 
ADD CONTENT
Topic
Content
Source link
Name
4+8 =