Guest User

Untitled

a guest
May 31st, 2018
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. "Branch1": 663134.44
  2.  
  3. "Branch1": 492784.54
  4.  
  5. "Branch1": 757639.93
  6.  
  7. "Branch1": 569404.61
  8.  
  9. <?php
  10. $dbhost = 'localhost';
  11. $dbname = 'spmdb';
  12. $dbuser = 'root';
  13. $dbpass = '';
  14.  
  15.  
  16. try{
  17.  
  18. $dbcon = new PDO("mysql:host={$dbhost};dbname={$dbname}",$dbuser,$dbpass);
  19. $dbcon->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  20.  
  21. }catch(PDOException $ex){
  22.  
  23. die($ex->getMessage());
  24. }
  25. $stmt = $dbcon->prepare("SELECT month.monthname,coll.branch,coll.cf FROM coll INNER JOIN month ON month.id = coll.`month` group by coll.month,coll.branch");
  26. $stmt->execute();
  27. $row1 = [];
  28. while($row=$stmt->fetch(PDO::FETCH_ASSOC))
  29. {
  30. extract($row);
  31. $row1[]= ['month' => $monthname, $branch => $cf];
  32.  
  33. }
  34. echo json_encode($row1,JSON_NUMERIC_CHECK);
  35. ?>
  36.  
  37. [{"month":"Jan","Branch4":40275}
  38. ,{"month":"Feb","Branch5":165173.91}
  39. ,{"month":"Feb","Branch1":93360.33}
  40. ,{"month":"Apr","Branch1":65415.75}]
Add Comment
Please, Sign In to add comment