Advertisement
Guest User

Untitled

a guest
Jul 6th, 2016
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. <?php
  2. $servername = "localhost";
  3. $username = "username";
  4. $password = "password";
  5. $dbname = "myDB";
  6.  
  7. // Create connection
  8. $conn = new mysqli($servername, $username, $password, $dbname);
  9.  
  10. // Check connection
  11. if( $conn->connect_error ) {
  12. die("Connection failed: " . $conn->connect_error);
  13. }
  14.  
  15. $sql = "SELECT `coordinates` FROM `MedMandatabase`";
  16. $result = $conn->query($sql);
  17.  
  18. if( $result->num_rows > 0 ) {
  19. // Create output base
  20. $output = "<script> var locations = [";
  21.  
  22. // output data of each row
  23. while( $row = $result->fetch_assoc() ) {
  24. echo "\"{$row['location']}\", ";
  25. }
  26.  
  27. // Create output last and print
  28. $output = substr($output, 0, -2);
  29. $output .= "];</script>";
  30. echo $output;
  31. } else {
  32. echo "0 results";
  33. }
  34.  
  35. $conn->close();
  36. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement