Advertisement
Guest User

Untitled

a guest
Apr 24th, 2014
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. <?php
  2.  
  3. function connecToDatabase(){
  4. $host = "localhost";
  5. $username = "root";
  6. $password = "p@ssword";
  7. $database = "flood_reports";
  8.  
  9. mysql_connect("$host", "$username", "$password") or die(mysql_error());
  10.  
  11. mysql_select_db("$database") or die(mysql_error());
  12. }
  13.  
  14. function retrieveData(){
  15. connecToDatabase();
  16. $data = mysql_query('SELECT * FROM entries') or die(mysql_error());
  17. $entries = array();
  18. $index = 0;
  19. while($info = mysql_fetch_array( $data ))
  20. {
  21. $entries[$index] = array('entry_id' => $info['entry_id'],
  22. 'location' => $info['location'],
  23. 'image_dir' => $info['image_dir'],
  24. 'longitude' => $info['longitude'],
  25. 'latitude' => $info['latitude'],
  26. 'level' => $info['level']);
  27. $index++;
  28. }
  29.  
  30. $json = json_encode($entries);
  31. echo $json;
  32.  
  33. mysql_close();
  34. }
  35.  
  36. retrieveData();
  37.  
  38. ?>
  39.  
  40. <script type="text/javascript">
  41. var jsvar = <?php echo $phpvar;?>
  42. </script>
  43.  
  44. echo $json;
  45.  
  46. echo 'var fromPhp = ' . $json . ';';
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement