Advertisement
Guest User

Untitled

a guest
Jul 7th, 2016
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.69 KB | None | 0 0
  1. function saveProfile (){
  2. var variableD = 'sample data';
  3. $.post("dbConn.php", { js: variableD});
  4. }
  5.  
  6. function post_to_url(path, params, method) {
  7. ...
  8. }
  9.  
  10. function saveProfile (){
  11.  
  12. var _profileId = 0;
  13. var _profileName = document.getElementById('nameProfile').value;
  14.  
  15. var queryArr=[];
  16. $(markersArray).each(function (index){
  17. //alert(markersArray[index].name);
  18.  
  19. var _locationId = index;
  20. var _locName = markersArray[index].name;
  21. var _markerLat = markersArray[index].marker.getLatLng().lat();
  22. var _markerLng = markersArray[index].marker.getLatLng().lng();
  23.  
  24. var locations = {
  25. profileName: _profileName,
  26. locationId:_locationId,
  27. locationName:_locName,
  28. lat:_markerLat,
  29. lng:_markerLng }
  30.  
  31. queryStr = { "locations": locations}
  32.  
  33. queryArr.push(queryStr);
  34.  
  35.  
  36. });
  37.  
  38. /*for ( var i=0; i<markersArray.length; i++){
  39. alert(queryArr[i].locations.locationId+"--"+queryArr[i].locations.locationName +"--"+queryArr[i].locations.lat);
  40. }*/
  41.  
  42. $.post('dbConn.php', { opType:"saveAsProfile" , data: queryArr}, showResult, "text");
  43.  
  44. }
  45.  
  46. $db_host = 'localhost';
  47. $db_user = 'root';
  48. $db_pass = '';
  49. $db_name = 'google_map_db';
  50.  
  51.  
  52.  
  53. $opType = $_POST['opType'];
  54.  
  55. //SAVE PROFILES WITH A PROFILE NAME
  56. if(!strcmp($opType, "saveAsProfile") ){
  57.  
  58. $res = $_POST['data'];
  59. $connect = mysql_connect( $db_host, $db_user, $db_pass ) or die( mysql_error() );
  60. mysql_select_db( $db_name ) or die( mysql_error() );
  61. $queryString = "";
  62.  
  63. for($i = 0; $i < sizeof($res); $i++){
  64.  
  65. $profileName = $res[$i]['locations']['profileName'];
  66. $locationId = $res[$i]['locations']['locationId'];
  67. $locationName = $res[$i]['locations']['locationName'];
  68. $lat = $res[$i]['locations']['lat'];
  69. $lng = $res[$i]['locations']['lng'];
  70.  
  71. $sp = " ";
  72. $queryString = $queryString . "(0 ".",'".$profileName."',".$locationId.",'".$locationName."',".$lat.",".$lng.") ";
  73.  
  74. if($i<sizeof($res)-1)
  75. $queryString = $queryString . ", ";
  76.  
  77. }
  78.  
  79.  
  80. $qInsertUser = mysql_query(" INSERT INTO `map_locations` (`profileId`, `profileName`, `locationId`, `locationName`, `lat`, `lng`)
  81. VALUES ".$queryString." ");
  82.  
  83. if ($qInsertUser){
  84. echo "successfully added!!!";
  85. } else {
  86. echo "Error";
  87. }
  88.  
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement