Advertisement
Guest User

Untitled

a guest
Mar 30th, 2016
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. <?php
  2. $username = "*****";
  3. $password = "******";
  4. $host = "localhost";
  5. $database="db";
  6.  
  7. $server = mysql_connect($host, $username, $password);
  8. $connection = mysql_select_db($database, $server);
  9.  
  10. $myquery = "
  11. SELECT `this`, `that` FROM `table`
  12. ";
  13. $query = mysql_query($myquery);
  14.  
  15. if ( ! $query ) {
  16. echo mysql_error();
  17. die;
  18. }
  19.  
  20. $data = array();
  21.  
  22. for ($x = 0; $x < mysql_num_rows($query); $x++) {
  23. $data[] = mysql_fetch_assoc($query);
  24. }
  25.  
  26. $fp = fopen('empdata.json', 'w');
  27. fwrite($fp, json_encode($data));
  28. fclose($fp);
  29.  
  30. mysql_close($server);
  31. ?>
  32.  
  33. d3.json("mypreviouslygeneratedjson.json", function (error, data) {
  34.  
  35. data.forEach(function (d)
  36. {
  37. ...
  38. }
  39.  
  40. echo json_encode($data);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement