Passing JavaScript Variables from JavaScript to PHP using AJAX - php

I am having some problems with my PHP file. So basically I am working on a project that takes two addresses from the user, then it uses javascript to show their route and once they click submit, I want to pass these two variables to PHP file. I researched a lot and found that I would need AJAX call. The problem I am running into is that AJAX call works perfectly, but when I go to PHP file it throws me an error that variables are not defined. Someone, please explain to me what I am doing wrong here.
JavaScript code:
/* ============================================================================================
Reference: https://developers.google.com/maps/documentation/javascript/examples/places-autocomplete-directions
==============================================================================================
*/
function initMap() {
var map = new google.maps.Map(document.getElementById('map'), {
mapTypeControl: false,
center: {lat: 41.881832, lng: -87.623177},
zoom: 13
});
new AutocompleteDirectionsHandler(map);
}
/**
* #constructor
*/
function AutocompleteDirectionsHandler(map) {
this.map = map;
this.originPlaceId = null;
this.destinationPlaceId = null;
this.travelMode = 'DRIVING';
var originInput = document.getElementById('origin-input');
var destinationInput = document.getElementById('destination-input');
var submit_button = document.getElementById('button-to-submit');
/*var modeSelector = document.getElementById('mode-selector');*/
this.directionsService = new google.maps.DirectionsService;
this.directionsDisplay = new google.maps.DirectionsRenderer;
this.directionsDisplay.setMap(map);
var originAutocomplete = new google.maps.places.Autocomplete(
originInput, {placeIdOnly: true});
var destinationAutocomplete = new google.maps.places.Autocomplete(
destinationInput, {placeIdOnly: true});
/*this.setupClickListener('changemode-walking', 'WALKING');
this.setupClickListener('changemode-transit', 'TRANSIT');
this.setupClickListener('changemode-driving', 'DRIVING');*/
this.setupPlaceChangedListener(originAutocomplete, 'ORIG');
this.setupPlaceChangedListener(destinationAutocomplete, 'DEST');
this.map.controls[google.maps.ControlPosition.TOP_LEFT].push(originInput);
this.map.controls[google.maps.ControlPosition.TOP_LEFT].push(destinationInput);
this.map.controls[google.maps.ControlPosition.TOP_LEFT].push(submit_button);
/*this.map.controls[google.maps.ControlPosition.TOP_LEFT].push(modeSelector);*/
}
// Sets a listener on a radio button to change the filter type on Places
// Autocomplete.
/* AutocompleteDirectionsHandler.prototype.setupClickListener = function(id, mode) {
var radioButton = document.getElementById(id);
var me = this;
radioButton.addEventListener('click', function() {
me.travelMode = mode;
me.route();
});
}; */
AutocompleteDirectionsHandler.prototype.setupPlaceChangedListener = function(autocomplete, mode) {
var me = this;
autocomplete.bindTo('bounds', this.map);
autocomplete.addListener('place_changed', function() {
var place = autocomplete.getPlace();
if (!place.place_id) {
window.alert("Please select an option from the dropdown list.");
return;
}
if (mode === 'ORIG') {
me.originPlaceId = place.place_id;
} else {
me.destinationPlaceId = place.place_id;
}
me.route();
});
};
AutocompleteDirectionsHandler.prototype.route = function() {
if (!this.originPlaceId || !this.destinationPlaceId) {
return;
}
var me = this;
this.directionsService.route({
origin: {'placeId': this.originPlaceId},
destination: {'placeId': this.destinationPlaceId},
travelMode: this.travelMode
}, function(response, status) {
if (status === 'OK') {
me.directionsDisplay.setDirections(response);
origin_addr = document.getElementById('origin-input').value;
//console.log(origin_addr);
destination_addr = document.getElementById('destination-input').value;
//console.log(destination_addr);
//var place_id = document.getElementById('origin-input');
} else {
window.alert('Directions request failed due to ' + status);
}
});
};
$("#button-to-submit").click(function() {
$.ajax({
url: "Database/save-points.php",
type: "POST", //send it through get method
data: {
origin_address: origin_addr,
destination_address: destination_addr
},
success: function(response) {
//Do Something
console.log("Succeed");
location.href="Database/save-points.php";
},
error: function(xhr) {
//Do Something to handle error
}
});
});
PHP code:
<?php
$origin_address = $_POST['origin_address'];
$destination_address = $_POST['destination_address'];
echo $origin_address;
echo $destination_address;
?>

/* maps.php */
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" lang="fr" dir="ltr">
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.js" type="text/javascript"></script>
<style>
/* Always set the map height explicitly to define the size of the div
* element that contains the map. */
#map {
height: 100%;
}
/* Optional: Makes the sample page fill the window. */
html, body {
height: 100%;
margin: 0;
padding: 0;
}
.controls {
margin-top: 10px;
border: 1px solid transparent;
border-radius: 2px 0 0 2px;
box-sizing: border-box;
-moz-box-sizing: border-box;
height: 32px;
outline: none;
box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
}
#origin-input,
#destination-input {
background-color: #fff;
font-family: Roboto;
font-size: 15px;
font-weight: 300;
margin-left: 12px;
padding: 0 11px 0 13px;
text-overflow: ellipsis;
width: 200px;
}
#origin-input:focus,
#destination-input:focus {
border-color: #4d90fe;
}
#mode-selector {
color: #fff;
background-color: #4d90fe;
margin-left: 12px;
padding: 5px 11px 0px 11px;
}
#mode-selector label {
font-family: Roboto;
font-size: 13px;
font-weight: 300;
}
</style>
</head>
<body>
<input id="origin-input" class="controls" type="text"
placeholder="Enter an origin location">
<input id="destination-input" class="controls" type="text"
placeholder="Enter a destination location">
<div id="mode-selector" class="controls">
<input type="radio" name="type" id="changemode-walking" checked="checked">
<label for="changemode-walking">Walking</label>
<input type="radio" name="type" id="changemode-transit">
<label for="changemode-transit">Transit</label>
<input type="radio" name="type" id="changemode-driving">
<label for="changemode-driving">Driving</label>
<input type="submit" id="button-to-submit" value="SAVE !" />
</div>
<div id="map"></div>
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key=YOU_KEY&libraries=places"></script>
<script type="text/javascript">
// This example requires the Places library. Include the libraries=places
// parameter when you first load the API. For example:
function initMap() {
var map = new google.maps.Map(document.getElementById('map'), {
mapTypeControl: false,
center: {lat: -33.8688, lng: 151.2195},
zoom: 13
});
new AutocompleteDirectionsHandler(map);
}
/**
* #constructor
*/
function AutocompleteDirectionsHandler(map) {
this.map = map;
this.originPlaceId = null;
this.destinationPlaceId = null;
this.travelMode = 'WALKING';
var originInput = document.getElementById('origin-input');
var destinationInput = document.getElementById('destination-input');
var modeSelector = document.getElementById('mode-selector');
this.directionsService = new google.maps.DirectionsService;
this.directionsDisplay = new google.maps.DirectionsRenderer;
this.directionsDisplay.setMap(map);
var originAutocomplete = new google.maps.places.Autocomplete(
originInput, {placeIdOnly: true});
var destinationAutocomplete = new google.maps.places.Autocomplete(
destinationInput, {placeIdOnly: true});
this.setupClickListener('changemode-walking', 'WALKING');
this.setupClickListener('changemode-transit', 'TRANSIT');
this.setupClickListener('changemode-driving', 'DRIVING');
this.setupPlaceChangedListener(originAutocomplete, 'ORIG');
this.setupPlaceChangedListener(destinationAutocomplete, 'DEST');
this.map.controls[google.maps.ControlPosition.TOP_LEFT].push(originInput);
this.map.controls[google.maps.ControlPosition.TOP_LEFT].push(destinationInput);
this.map.controls[google.maps.ControlPosition.TOP_LEFT].push(modeSelector);
}
// Sets a listener on a radio button to change the filter type on Places
// Autocomplete.
AutocompleteDirectionsHandler.prototype.setupClickListener = function(id, mode) {
var radioButton = document.getElementById(id);
var me = this;
radioButton.addEventListener('click', function() {
me.travelMode = mode;
me.route();
});
};
AutocompleteDirectionsHandler.prototype.setupPlaceChangedListener = function(autocomplete, mode) {
var me = this;
autocomplete.bindTo('bounds', this.map);
autocomplete.addListener('place_changed', function() {
var place = autocomplete.getPlace();
if (!place.place_id) {
window.alert("Please select an option from the dropdown list.");
return;
}
if (mode === 'ORIG') {
me.originPlaceId = place.place_id;
} else {
me.destinationPlaceId = place.place_id;
}
me.route();
});
};
AutocompleteDirectionsHandler.prototype.route = function() {
if (!this.originPlaceId || !this.destinationPlaceId) {
return;
}
var me = this;
this.directionsService.route({
origin: {'placeId': this.originPlaceId},
destination: {'placeId': this.destinationPlaceId},
travelMode: this.travelMode
}, function(response, status) {
if (status === 'OK') {
me.directionsDisplay.setDirections(response);
} else {
window.alert('Directions request failed due to ' + status);
}
});
};
/************************************/
$(document).ready( function() {
$("#button-to-submit").click(function() {
origin_addr = $("#origin-input").val();
destination_addr = $("#destination-input").val();
$.ajax({
type: "POST",
url: "maps.exe.php",
data: {
origin_address: origin_addr,
destination_address: destination_addr
},
success: function(response){
alert(response);
window.location.href = 'test-resp.php?'+response;
}
});
return false;
});
});
</script>
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key=YOUR_KEY&libraries=places&callback=initMap" async defer></script>
</body>
</html>
/* maps.exe.php */
<?php
$origin_address = $_POST['origin_address'];
$destination_address = $_POST['destination_address'];
echo"origin=$origin_address&destination=$destination_address";
?>
/* test-resp.php */
<?php
$origin_address = $_GET['origin'];
$destination_address = $_GET['destination'];
echo"[ origin : $origin_address / destination = $destination_address ]";
?>

I have an example of me passing JS variable to PHP.
JS (url and content are JS variables) :
var data_to_send = {
filepath: ""+url,
filecontent: ""+content
};
jQuery.ajax({
url:"php/dynamic.php",
data: data_to_send,
cache: false,
async: true,
type:'post',
timeout:3000//purely optionnal, check jQuery's Doc to learn more about ajax optionnal parameters/settings
});
In dynamic.php :
<?php
$vars = serialize($_POST); /*easier access*/
$file_path = "../".$vars["filepath"];
$file_content = $var["filecontent"]; /*example of assigning a JS var's value to a PHP var*/
$fh = fopen($file_path, 'w+') or die("could not open file");
fwrite($fh, $file_content."\n");
fclose($fh);
?>
PS: I use jQuery for POST, I dunno the pure javascript way to do the same :/

Related

On the click of the image it is not removing in jQuery

Selecting the multiple image from the input tag after that I am previewing the selected image but when I click on that image it should delete from the input tag it does not select that picture any more. But in my case that picture is removing only in preview not in input. And save it into database
Here is the code
<?php
include_once 'Functions.php';
$connect=new Connection();
$link=$connect->Connect();
print_r($_FILES['fil']['name']);
?>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.0/jquery.min.js"></script>
<script>
$(document).ready(function(){
var image=('')
('input[type="file"]'). change(function(e){
var fileName = e. target. files[0]. name;
alert('The file "' + fileName + '" has been selected.' );
});
$(function() {
var imagesPreview = function(input,placeToInsertImagePreview) {
if (input.files) {
var filesAmount = input.files.length;
for (i = 0; i < filesAmount; i++) {
var reader = new FileReader();
reader.onload = function(event) {
$($.parseHTML('<img class="picture" width="70" name="multipic">')).attr('src', event.target.result).appendTo(placeToInsertImagePreview);
$('.picture').click(function(){
$(this).remove();
});
}
reader.readAsDataURL(input.files[i]);
}
}
};
$('#gallery-photo-add').on('change', function() {
imagesPreview(this,'div.gallery');
});
});
});
</script>
</head>
<body>
<form name="update" enctype='multipart/form-data' method="POST">
<input type="file" name="fil[]" multiple id="gallery-photo-add" class="a1">
<div class="gallery"></div>
<input type="submit" name="btnupdate" value="Update" />
</form>
</body>
</html>
Here is HTML Code :
<div class="container">
<form id="fileupload" action="#" method="POST" enctype="multipart/form-data">
<div class="row files" id="files1">
<h2>Files 1</h2>
<span class="btn btn-default btn-file">
Browse <input type="file" name="files1" multiple />
</span><br/>
<ul class="fileList"></ul>
</div>
<div class="row">
<button type="x" id="uploadBtn" class="btn primary start">Start upload</button>
</div>
<div class="row">
<div class="span16">
<table class="zebra-striped"><tbody class="files"></tbody></table>
</div>
</div>
</form>
</div>
Here is CSS Code :
.btn-file {
position: relative;
overflow: hidden;
}
.btn-file input[type=file] {
position: absolute;
top: 0;
right: 0;
min-width: 100%;
min-height: 100%;
font-size: 100px;
text-align: right;
filter: alpha(opacity=0);
opacity: 0;
outline: none;
background: white;
cursor: inherit;
display: block;
}
Here is jQuery Code :
$.fn.fileUploader = function (filesToUpload, sectionIdentifier) {
var fileIdCounter = 0;
this.closest(".files").change(function (evt) {
var output = [];
for (var i = 0; i < evt.target.files.length; i++) {
fileIdCounter++;
var file = evt.target.files[i];
var fileId = sectionIdentifier + fileIdCounter;
filesToUpload.push({
id: fileId,
file: file
});
var removeLink = "<a class=\"removeFile\" href=\"#\" data-fileid=\"" + fileId + "\">Remove</a>";
output.push("<li><strong>", escape(file.name), "</strong> - ", file.size, " bytes. ", removeLink, "</li> ");
};
$(this).children(".fileList")
.append(output.join(""));
//reset the input to null - nice little chrome bug!
evt.target.value = null;
});
$(this).on("click", ".removeFile", function (e) {
e.preventDefault();
var fileId = $(this).parent().children("a").data("fileid");
// loop through the files array and check if the name of that file matches FileName
// and get the index of the match
for (var i = 0; i < filesToUpload.length; ++i) {
if (filesToUpload[i].id === fileId)
filesToUpload.splice(i, 1);
}
$(this).parent().remove();
});
this.clear = function () {
for (var i = 0; i < filesToUpload.length; ++i) {
if (filesToUpload[i].id.indexOf(sectionIdentifier) >= 0)
filesToUpload.splice(i, 1);
}
$(this).children(".fileList").empty();
}
return this;
};
(function () {
var filesToUpload = [];
var files1Uploader = $("#files1").fileUploader(filesToUpload, "files1");
$("#uploadBtn").click(function (e) {
e.preventDefault();
var formData = new FormData();
for (var i = 0, len = filesToUpload.length; i < len; i++) {
formData.append("files", filesToUpload[i].file);
}
$.ajax({
url: "",
data: formData,
processData: false,
contentType: false,
type: "POST",
success: function (data) {
alert("DONE");
files1Uploader.clear();
},
error: function (data) {
alert("ERROR - " + data.responseText);
}
});
});
});
Try above code. Hope this will help

Updated the jquery array to the hidden field using jquery

I Have Multi-selcet Box. this my Html code:
<section class="container">
<div>
<select id="leftValues" name="leftValues[]" size="5" multiple>
<option value="a">1</option>
<option value="b">2</option>
<option value="c">3</option>
</select>
<input type="hidden" id="txtLeft" name=txtLeft/>
</div>
<div>
<input type="button" id="btnLeft" value="<<" />
<input type="button" id="btnRight" value=">>" />
</div>
<div>
<select id="rightValues" name=rightValues[] size="4" multiple>
<option value="x">9</option>
<option value="y">8</option>
<option value="z">7</option>
</select>
<div>
<input type="hidden" id="txtRight" name=txtRight/>
</div>
</div>
</section>
<button type="submit" id="value" class="blue">Save</button>
This what the jQuery I have tried. I want the all the value in the array addedLeftValues to be updated to txtLeft and values in addedRightValues to be updated to txtRight when I click on the Save button.
<script>
var left;
var right;
var newLeft;
var newRight;
var addedLeftValues = new Array();
var addedRightValues = new Array();
$(document).ready(function() {
SaveOldValues();
});
function SaveOldValues()
{
left = new Array();
right = new Array();
$('#leftValues .left').each(function(){
left.push($(this).val());
});
$('#rightValues .right').each(function(){
right.push($(this).val());
});
}
function UpdatedValues()
{
newLeft = new Array();
newRight = new Array();
$('#leftValues .left').each(function(){
newLeft.push($(this).val());
});
$('#rightValues .right').each(function(){
newRight.push($(this).val());
});;
}
$("#btnLeft").click(function () {
var selectedItem = $("#rightValues option:selected");
$(selectedItem).attr("class","left");
$("#leftValues").append(selectedItem);
});
$("#btnRight").click(function () {
var selectedItem = $("#leftValues option:selected");
$(selectedItem).attr("class","right");
$("#rightValues").append(selectedItem);
});
$("#rightValues").change(function () {
var selectedItem = $("#rightValues option:selected");
});
$("#value").on("click",function(){
UpdatedValues();
$(newLeft).each(function(k,value){
if($.inArray(value, left) == -1)
{
alert("new value in left is: " + value);
addedLeftValues.push(value);
$("#txtLeft").val(function(i, v) {
arr.push(addedLeftValues);
});
}
});
$(newRight).each(function(k,value){
if($.inArray(value, right) == -1)
{
alert("new value in Right is: " + value);
addedRightValues.push(value);
$("#txtRight").val(function(i, v) {
arr.push(addedRightValues);
});
}
});
});
And this is my CSS code:
<style>
SELECT, INPUT[type="text"] {
width: 160px;
box-sizing: border-box;
}
SECTION {
padding: 8px;
background-color: #f0f0f0;
overflow: auto;
}
SECTION > DIV {
float: left;
padding: 4px;
}
SECTION > DIV + DIV {
width: 40px;
text-align: center;
}
</style>
it seems to works when you put all your codes inside the dome ready method
$(function () {
var left;
var right;
var newLeft;
var newRight;
var addedLeftValues = new Array();
var addedRightValues = new Array();
SaveOldValues();
function SaveOldValues() {
left = new Array();
right = new Array();
$('#leftValues .left').each(function () {
left.push($(this).val());
});
$('#rightValues .right').each(function () {
right.push($(this).val());
});
}
function UpdatedValues() {
newLeft = new Array();
newRight = new Array();
$('#leftValues .left').each(function () {
newLeft.push($(this).val());
});
$('#rightValues .right').each(function () {
newRight.push($(this).val());
});;
}
$("#btnLeft").click(function () {
var selectedItem = $("#rightValues option:selected");
$(selectedItem).attr("class", "left");
$("#leftValues").append(selectedItem);
});
$("#btnRight").click(function () {
var selectedItem = $("#leftValues option:selected");
$(selectedItem).attr("class", "right");
$("#rightValues").append(selectedItem);
});
$("#value").click(function () {
UpdatedValues();
$(newLeft).each(function (k, value) {
if ($.inArray(value, left) == -1) {
alert("new value in left is: " + value);
addedLeftValues.push(value);
$("#txtLeft").val(function (i, v) {
arr.push(addedLeftValues);
});
}
});
$(newRight).each(function (k, value) {
if ($.inArray(value, right) == -1) {
alert("new value in Right is: " + value);
addedRightValues.push(value);
$("#txtRight").val(function (i, v) {
arr.push(addedRightValues);
});
}
});
});
});
but then you'll be faced by a new error on line 54 and line 64 arr.push(addedRightValues); ReferenceError: arr is not defined
check it on fiddlejs http://jsfiddle.net/p6MKv/

trouble passing php variable to modal window

Hi I'm using the following code to load the file modal_window.php into a modal window on the current page.
<style>
* {
margin:0;
padding:0;
}
#overlay {
position:fixed;
top:0;
left:0;
width:100%;
height:100%;
background:#000;
opacity:0.5;
filter:alpha(opacity=50);
}
#modal {
position:absolute;
background:url(tint20.png) 0 0 repeat;
background:rgba(0,0,0,0.2);
border-radius:14px;
padding:8px;
}
#content {
border-radius:8px;
background:#fff;
padding:20px;
}
#close {
position:absolute;
background:url(close.png) 0 0 no-repeat;
width:24px;
height:27px;
display:block;
text-indent:-9999px;
top:-7px;
right:-7px;
}
</style>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js">
</script>
<script>
var modal = (function(){
var
method = {},
$overlay,
$modal,
$content,
$close;
// Center the modal in the viewport
method.center = function () {
var top, left;
top = Math.max($(window).height() - $modal.outerHeight(), 0)
/ 2;
left = Math.max($(window).width() - $modal.outerWidth(), 0)
/ 2;
$modal.css({
top:top + $(window).scrollTop(),
left:left + $(window).scrollLeft()
});
};
// Open the modal
method.open = function (settings) {
$content.append(settings.content);
$modal.css({
width: settings.width || 'auto',
height: settings.height || 'auto'
})
method.center();
$(window).bind('resize.modal', method.center);
$modal.show();
$overlay.show();
};
// Close the modal
method.close = function () {
$modal.hide();
$overlay.hide();
$content.empty();
$(window).unbind('resize.modal');
};
// Generate the HTML and add it to the document
$overlay = $('<div id="overlay"></div>');
$modal = $('<div id="modal"></div>');
$content = $('<div id="content"></div>');
$close = $('<a id="close" href="#">close</a>');
$modal.hide();
$overlay.hide();
$modal.append($content, $close);
$(document).ready(function(){
$('body').append($overlay,
$modal);
});
$close.click(function(e){
e.preventDefault();
method.close();
});
return method;
}());
// Wait until the DOM has loaded before querying the document
$(document).ready(function(){
varid = '<?php if(isset($_GET['id'])); ?>';
$('a#testmodal').click(function(e){
$.get('modal_window.php?id=varid', function(data){
modal.open({content: data});});
e.preventDefault();
});
});
</script>
</head>
<body>
<a id="testmodal" href="modal.php?id=1">Test</a>
While doing so I'm attempting to pass the variable $id to modal_window.php using :
varid = '<?php if(isset($_GET['id'])); ?>';
and then
$('a#testmodal').click(function(e){
$.get('modal_window.php?id=varid', function(data){
modal.open({content: data});});
e.preventDefault();
});
Instead of the actual value of $id (1 in this case) getting passed to modal_window.php what is getting passed is the name of the java script variable (varid). So "varid" is what is being displayed by modal_window.php. Does anyone see the mistake I'm making? Thanks!
In your get call you have id equal to the literal varid. Instead maybe
$.get('modal_window.php?id=' + varid, function(data){
modal.open({content: data});});
e.preventDefault();
});

jQuery doesnt work at all in IE8

I have read lots of past postings on this subject...
I have tried every "solution", change to type="text/javascript", upgrade it to the latest version, including this header <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" /> but nothing seems to work.
The site is testing.quierodecomer.com
NOTE: I wrote <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE8" /> in the head for testing issues.
<?php
session_start();
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE8" />
<title>Quiero de comer!</title>
<link href="favicon.png" type="image/png" rel="icon">
<style>
.ui-autocomplete-loading { background: white url('jquery-ui-1.8.21.custom/css/ui-lightness/images/ui-anim_basic_16x16.gif') right center no-repeat;
}
</style>
<link rel="stylesheet" type="text/css" href="jquery-ui-1.8.21.custom/css/ui-lightness/jquery-ui-1.8.21.custom.css" />
<link rel="stylesheet" type="text/css" href="css/stylesheet.css" />
<link rel="stylesheet" type="text/css" href="css/fonts.css" />
<link rel="stylesheet" type="text/css" href="css/jquery.imageZoom.css" />
<style type="text/css">
body {
padding: 0px;
vertical-align:bottom;
}
#container {
position: absolute;
margin: 0px;
padding: 0px;
width: 100%;
height: 360px;
overflow: hidden;
text-align:center;
}
.box {
position: absolute;
width: 400px;
height: 200px;
line-height: 40px;
font-size: 30px;
font-weight:bold;
color:black;
text-align: center;
border: 3px solid grey;
left: 50%;
top: 100px;
-webkit-border-radius:60px;
-moz-border-radius:60px;
border-radius:60px;
margin-top:-70px;
margin-left: -200px;
}
#box1 {
background-color:#FFF;
}
#box2 {
background-color:#FFF;
left: 150%;
}
#box3 {
background-color:#FFF;
left: 150%;
}
.btn1, .coloniaButton{
background:#ff5d35;
border:none;
-webkit-border-radius:10px;
-moz-border-radius:10px;
border-radius:10px;
vertical-align:middle;
cursor:pointer;
color:#fff;
font-weight:bold;
font-size:20px;
padding:5px 10px;
margin-right:-225px;
border: 1px solid #000;
}
.btn1:hover, .coloniaButton:hover{
background:#3f3f3f;
}
#tags, #tipoDeComida, #tags2, #city {
padding:.8em;
-moz-border-radius: 10px 10px 10px 10px;
-webkit-border-radius: 10px 10px 10px 10px;
border-radius: 10px 10px 10px 10px;
border:none;
width:350px;
margin-bottom:5px;
border: 2px solid grey;
}
.titulo{
margin-top: 23px;
}
.caja{
margin-top: 20px;
}
.servicios{
font-size:15px;
font-weight:bold;
}
#ciudadBreadcrumb, #coloniaBreadcrumb{
font-size: 15px;
}
#footer{
text-align: center;
background-color: black;
width: 99.2%;
padding: 5px;
color: white;
position: absolute;
bottom: 0px;
}
</style>
<link rel="stylesheet" href="css/supersized.css" type="text/css" media="screen" />
<link rel="stylesheet" href="theme/supersized.shutter.css" type="text/css" media="screen" />
<link rel="stylesheet" href="css/flexslider.css" type="text/css">
<script type="text/javascript" src="jquery-ui-1.8.21.custom/js/jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="jquery-ui-1.8.21.custom/js/jquery-ui-1.8.21.custom.min.js"></script>
<script type="text/javascript" src="jquery-ui-1.8.21.custom/js/jquery.paginatetable.js"></script>
<script type="text/javascript" src="jquery-ui-1.8.21.custom/js/md5.js"></script>
<script type="text/javascript" src="js/jquery.flexslider.js"></script>
<script type="text/javascript" src="js/jquery.easing.min.js"></script>
<script type="text/javascript" src="js/supersized.3.2.6.min.js"></script>
<script type="text/javascript" src="theme/supersized.shutter.min.js"></script>
<script type="text/javascript" src="js/jquery.imageZoom.js"></script>
<?php
include("conecta.php");
$result = mysql_query("SELECT * FROM fondo WHERE id = 1");
while($row = #mysql_fetch_array($result)){
$fondo = $row['imgFondo'];
}
?>
<script type="text/javascript">
jQuery(function($){
$.supersized({
// Functionality
slide_interval : 3000, // Length between transitions
transition : 1, // 0-None, 1-Fade, 2-Slide Top, 3-Slide Right, 4-Slide Bottom, 5-Slide Left, 6-Carousel Right, 7-Carousel Left
transition_speed : 700, // Speed of transition
// Components
slide_links : 'blank', // Individual links for each slide (Options: false, 'num', 'name', 'blank')
slides : [ // Slideshow Images
{image : 'admin/uploads/fondos/<?php echo $fondo; ?>', title : '', thumb : '', url : ''}
]
});
});
</script>
<script type="text/javascript">
$(document).ready(function(){
$("#colonia").hide();
$('.btn1').click(function() {
$('.box').each( function() {
if ($(this).offset().left < 0) {
$(this).css("left", "150%");
}
});
$(this.parentNode).animate({
left: '-50%'
}, 500);
if ($(this.parentNode).next().size() > 0) {
$(this.parentNode).next().animate({
left: '50%'
}, 500);
} else {
$(this.parentNode).prevAll().last().animate({
left: '50%'
}, 500);
}
});
$('#domicilio').click(function() {
$('.box').each( function() {
if ($(this).offset().left < 0) {
$(this).css("left", "150%");
}
});
$(this.parentNode.parentNode).animate({
left: '-50%'
}, 500);
if ($(this.parentNode.parentNode).next().size() > 0) {
$(this.parentNode.parentNode).next().animate({
left: '50%'
}, 500);
} else {
$(this.parentNode.parentNode).prevAll().last().animate({
left: '50%'
}, 500);
}
});
$('#colonia').click(function() {
setCookie("domicilio", "tipoDeServicio");
});
$('#ciudad').click(function() {
var e = document.getElementById("city");
var city = e.options[e.selectedIndex].value;
setCookie(city, "puraCiudad");
});
jQuery(document.body).imageZoom();
$('#pager').hide();
clienteBar();
$("#crossCiudad").hide();
$("#crossColonia").hide();
loadBreadcrumbs();
getTipoDeComida();
getCiudades();
$("#enviarSignUp").button();
$( "#logInContainer" ).dialog({
autoOpen: false,
height: 420,
width: 750,
modal: true,
buttons: {
"Regresar": function() {
$( this ).dialog( "close" );
}
},
});
$("#afiliarte").dialog({
autoOpen: false,
height: 350,
width: 450,
modal: true,
buttons: {
"Enviar": function() {
//function
},
"Regresar": function() {
$( this ).dialog( "close" );
}
},
});
$("#contactanos").dialog({
autoOpen: false,
height: 350,
width: 450,
modal: true,
buttons: {
"Enviar": function() {
//function
},
"Regresar": function() {
$( this ).dialog( "close" );
}
},
});
$( "#sugerirRestaurantes" ).dialog({
autoOpen: false,
height: 350,
width: 450,
modal: true,
buttons: {
"Enviar": function() {
//function
},
"Regresar": function() {
$( this ).dialog( "close" );
}
},
});
$( "#terminosCondiciones" ).dialog({
autoOpen: false,
height: 350,
width: 450,
modal: true,
});
$( "#signUpContainer" ).dialog({
autoOpen: false,
height: 320,
width: 480,
modal: true,
buttons: {
"Enviar": function() {
signUp();
},
"Regresar": function() {
document.getElementById("notificationCC").value = "";
$( this ).dialog( "close" );
}
},
})
});
function logInDialog(){
$( "#logInContainer" ).dialog( "open" );
}
function sugerirRestaurantesDialog(){
$( "#sugerirRestaurantes" ).dialog( "open" );
}
function terminosCondicionesDialog(){
$( "#terminosCondiciones" ).dialog( "open" );
}
function afiliarteDialog(){
$( "#afiliarte" ).dialog( "open" );
}
function contactanosDialog(){
$( "#contactanos" ).dialog( "open" );
}
function signUpDialog(){
$( "#signUpContainer" ).dialog( "open" );
}
function send(str, flag){
if (window.XMLHttpRequest){
xmlhttp = new XMLHttpRequest();
}
else{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function(){
if (xmlhttp.readyState==4 && xmlhttp.status==200){
//callback
//xmlhttp.responseText
switch(flag){
case "setCookie": setCookieCallback(xmlhttp.responseText);break;
case "deleteCookie": deleteCookieCallback(xmlhttp.responseText); break;
case "loadBreadcrumbs": loadBreadcrumbsCallback(xmlhttp.responseText);break;
case "getRestaurantes": getRestaurantesCallback(xmlhttp.responseText);break;
case "logIn": logInCallback(xmlhttp.responseText);break;
case "signUp": signUpCallback(xmlhttp.responseText);break;
case "logOut": logOutCallback(xmlhttp.responseText);break;
}
}
}
xmlhttp.open("GET",str,true);
xmlhttp.send();
}
function loadBreadcrumbs(){
//Checkboxes
if(document.getElementById('domicilioBreadcrumb').value == "set"){
document.getElementById('domicilio').checked = true;
}
if(document.getElementById('recogerBreadcrumb').value == "set"){
document.getElementById('recoger').checked = true;
}
if(document.getElementById('reservacionBreadcrumb').value == "set"){
document.getElementById('reservacion').checked = true;
}
var str = "printCookie.php";
send(str, "loadBreadcrumbs");
}
function loadBreadcrumbsCallback(response){
var arr = response.split("/");
//alert(response);
var colonia = arr[0].split("=");
var ciudad = arr[1].split("=");
var estado = arr[2].split("=");
var tipoDeComida = arr[3].split("=");
if(colonia[1] != ""){
document.getElementById("coloniaBreadcrumb").innerHTML = colonia[1]+"<br />";
$("#colonia").show();
}
if(ciudad[1] != ""){
document.getElementById("ciudadBreadcrumb").innerHTML = ciudad[1] + ", " + estado[1]+"<br />";
}
//document.getElementById("tipoDeComidaBreadcrumb").innerHTML = tipoDeComida[1];
if(document.getElementById('ciudadBreadcrumb').innerHTML == ""){
$("#crossCiudad").hide();
} else {
$("#city").hide();
$("#crossCiudad").show();
}
if(document.getElementById('coloniaBreadcrumb').innerHTML == ""){
$("#crossColonia").hide();
} else {
$("#tags2").hide();
$("#crossColonia").show();
}
//alert(colonia[1]+", "+ciudad[1]+", "+tipoDeComida[1]);
//getRestaurantes(colonia[1], ciudad[1], tipoDeComida[1]);
}
function handleSearch(event, ui){
term = document.getElementById("tags").value;
$.ajax({
url: 'loadCiudades.php?term='+term,
success: function(data) {
if(data == '[]'){
restaurantes = document.getElementById("content-background");
imagen = document.getElementById("proximamente");
restaurantes.style.display = "none";
imagen.style.display = "block";
}else{
restaurantes = document.getElementById("content-background");
imagen = document.getElementById("proximamente");
restaurantes.style.display = "block";
imagen.style.display = "none";
}
}
});
}
function getCiudades(){
ciudad = "<?php echo $_COOKIE['ciudad']; ?>";
$( "#tags2" ).autocomplete({
source: "loadCiudades.php?ciudad="+ciudad,
select: function(event, ui) {
setCookie(ui.item.value, "ciudad");
},
search: function(event, ui){ handleSearch(event,ui); }
});
}
function getTipoDeComida(){
$("#tipoDeComida").autocomplete({
source: "loadTipoDeComida.php",
select: function(event, ui) {
setCookie(ui.item.value, "tipoDeComida");
}
});
}
function setCookie(cookieValue, cookieType){
var str = "setCookie.php?cookieValue=" + cookieValue + "&cookieType=" + cookieType;
send(str, "setCookie");
}
function setCookieCallback(response){
switch(response){
case "puraCiudad": document.getElementById("tags").value = "";
$("#crossCiudad").show();
$("#city").hide();
break;
case "tipoDeComida": document.getElementById("tipoDeComida").value = "";
$("#crossComida").show();
$("#tipoDeComida").hide();
break;
case "ciudad": document.getElementById("tags2").value = "";
$("#crossColonia").show();
$("#tags2").hide();
$("#colonia").hide();
break;
case "tipoDeServicio": parent.location='index2.php';
break;
}
loadBreadcrumbs();
}
function getRestaurantes(colonia2, ciudad2, tipo2){
var direccion = document.getElementById('tags').value;
//var colonia = direccion.split(',')[0];
//var ciudad = direccion.split(',')[1];
var colonia = trim(colonia2);
var ciudad = trim(ciudad2);
var tipoComida = trim(tipo2);
var str = "getRestaurantes.php?colonia=" + colonia + "&ciudad=" + ciudad + "&tipoComida=" + tipoComida;
send(str, "getRestaurantes");
}
function getRestaurantesCallback(response){
if(response == "empty"){
document.getElementById('paging').innerHTML = "";
$('#pager').hide();
} else {
var arr = response.split("|");
var restaurantes = arr[0];
var promociones = arr[1];
var numPag = arr[2]/4;
document.getElementById("promocionesContainer").innerHTML = promociones;
$('#pager').show();
document.getElementById('paging').innerHTML = restaurantes;
$('#myTable').paginateTable({ rowsPerPage: numPag });
if(document.getElementById('totalPages').innerHTML == ""){
document.getElementById('pager').style.display = "none";
} else {
document.getElementById('pager').style.display = "block";
}
}
}
function stripVowelAccent(str)
{
var rExps=[
{re:/[\xC0-\xC6]/g, ch:'A'},
{re:/[\xE0-\xE6]/g, ch:'a'},
{re:/[\xC8-\xCB]/g, ch:'E'},
{re:/[\xE8-\xEB]/g, ch:'e'},
{re:/[\xCC-\xCF]/g, ch:'I'},
{re:/[\xEC-\xEF]/g, ch:'i'},
{re:/[\xD2-\xD6]/g, ch:'O'},
{re:/[\xF2-\xF6]/g, ch:'o'},
{re:/[\xD9-\xDC]/g, ch:'U'},
{re:/[\xF9-\xFC]/g, ch:'u'},
{re:/[\xD1]/g, ch:'N'},
{re:/[\xF1]/g, ch:'n'} ];
for(var i=0, len=rExps.length; i<len; i++)
str=str.replace(rExps[i].re, rExps[i].ch);
return str;
}
function deleteCookie(cookieType){
var str = "deleteCookie.php?cookieType=" + cookieType;
send(str, "deleteCookie");
}
function deleteCookieCallback(response){
//Borra el breadcrumb
switch(response){
case "puraCiudad": document.getElementById("ciudadBreadcrumb").innerHTML = "";
$("#crossCiudad").hide();
$("#city").show();
break;
case "tipoDeComida": document.getElementById("tipoDeComidaBreadcrumb").innerHTML = "";
$("#crossComida").hide();
$("#tipoDeComida").show();
break;
case "ciudad": document.getElementById("coloniaBreadcrumb").innerHTML = "";
$("#crossColonia").hide();
$("#tags2").show();
$("#colonia").hide();
break;
}
getRestaurantes();
}
function setCookieCheck(check, cookieType){
if(check.checked){
setCookie(1, cookieType);
} else {
deleteCookie(cookieType);
}
}
function logIn(){
var email = document.getElementById("email").value;
var password = document.getElementById("password").value;
if(email == "" || password == ""){
document.getElementById("notification").innerHTML = "Ingresa tu email y contraseña";
} else {
password = hex_md5(password);
var str = "logIn.php?password=" + password + "&email=" + email;
send(str, "logIn");
}
}
function logInCallback(response){
if(response == "not_logged/0"){
document.getElementById("notification").innerHTML = "Las credenciales no son válidas";
} else {
document.getElementById("notification").innerHTML = "";
$("#logInBar").hide();
$("#logInBarMenu").hide();
$("#signUpBar").hide();
$("#clienteBar").show();
arr = response.split("/");
document.getElementById("usuarioIDnombre").innerHTML = arr[1];
$("#logInContainer").dialog("close");
loadColonia();
}
}
function loadColonia(){
var str = "getColonia.php";
send(str, "colonia");
}
function loadColoniaCallback(response){
}
function clienteBar(){
if(document.getElementById('usuarioID').value == 0){
$("#clienteBar").hide();
} else {
$("#logInBar").hide();
$("#signUpBar").hide();
}
}
function signUp(){
var valido = validateSignUp();
if(valido == true){
var nombre = document.getElementById("nombreCC").value;
var direccion = document.getElementById("direccionCC").value;
var email = document.getElementById("emailCC").value;
var password1 = document.getElementById("password1").value;
var nacimiento = document.getElementById("dia").value + "/" + document.getElementById("mes").value + "/" + document.getElementById("anio").value;
var sexo = document.getElementById("sexo").value;
var telefono = document.getElementById("telefono").value;
var str = "signUp.php?nombre=" + nombre + "&direccion=" + direccion + "&email=" + email + "&password=" + password1 + "&nacimiento=" + nacimiento + "&sexo=" + sexo + "&telefono=" + telefono;
send(str, "signUp");
}
}
function signUpCallback(response){
if(response == "existingEmail"){
document.getElementById("notificationCC").innerHTML = "Esa dirección de correo ya ha sido utilizada";
} else {
document.getElementById("notificationCC").innerHTML = "Ingresa a tu email para dar de alta tu cuenta";
document.getElementById("nombreCC").value = "";
document.getElementById("emailCC").value = "";
password1 = document.getElementById("password1").value = "";
password1 = document.getElementById("password2").value = "";
}
}
function validateSignUp(){
var nombre = document.getElementById("nombreCC").value;
var direccion = document.getElementById("direccionCC").value;
var email = document.getElementById("emailCC").value;
var password1 = document.getElementById("password1").value;
var password2 = document.getElementById("password2").value;
var dia = document.getElementById("dia").value;
var mes = document.getElementById("mes").value;
var anio = document.getElementById("anio").value;
var sexo = document.getElementById("sexo").value;
var telefono = document.getElementById("telefono").value;
var mydate=new Date()
var year=mydate.getYear();
if (year < 1000){
year+=1900
}
var month = mydate.getMonth();
month = month + 1;
var day = mydate.getDate();
if(day > 31 || mes > 12 || anio >= year){
document.getElementById("notificationCC").innerHTML = "La fecha de nacimiento no es válida";
return false;
} else{
//Valida que todos los campos esten llenos
if(nombre == "" || email == "" || password1 == "" || password2 == "" || telefono == "" || direccion == ""){
document.getElementById("notificationCC").innerHTML = "Por favor llena todos los campos";
return false;
} else {
//Passwords iguales
if(password1 != password2){
document.getElementById("notificationCC").innerHTML = "Las contraseñas no coinciden";
return false;
} else {
//Longitud del password
if(password1.length < 6){
document.getElementById("notificationCC").innerHTML = "La contraseña debe ser de al menos 6 caracteres de largo";
return false;
} else {
if(comparaFecha(dia, mes, anio, day, month, year) == false){
document.getElementById("notificationCC").innerHTML = "La fecha no es correcta";
return false;
}
else{
if(telefono.length < 10){
document.getElementById("notificationCC").innerHTML = "El telefono no es correcto";
return false;
} else {
return true;
}
}
}
}
}
}
}
function trim(value) {
var temp = value;
var obj = /^(\s*)([\W\w]*)(\b\s*$)/;
if (obj.test(temp)) { temp = temp.replace(obj, '$2');}
var obj = / /g;
while (temp.match(obj)) { temp = temp.replace(obj, " ");}
return temp;
}
function comparaFecha(dia, mes, anio, day, month, year){
if(anio > (year-18)){
return false;
}
else
{
if(anio == (year-18))
{
if(mes > month){
return false;
}
else
{
if(mes == month)
{
if(dia > day){
return false;
}
else
{
return true;
}
}
}
}
else
{
return true;
}
}
}
function logOut(){
var str = "logOut.php";
send(str, "logOut");
}
function logOutCallback(response){
if(response == "success"){
$("#clienteBar").hide();
$("#logInBar").show();
$("#logInBarMenu").show();
$("#signUpBar").show();
document.getElementById("usuarioID").value = 0;
}
}
function setServicio(tipo){
setCookie("check", tipo);
}
function redirect(element){
window.location = element.title;
}
</script>
</head>
<?php
include("indexBackend.php");
?>
<body>
<?php
//Carga la session
if(isset($_SESSION['usuarioID'])){
echo ("<input type='hidden' id='usuarioID' value='".$_SESSION['usuarioID']."' />");
$nombre = $_SESSION['nombre'];
} else {
echo ("<input type='hidden' id='usuarioID' value='0' />");
$nombre = "";
}
?>
<?php
include("getPublicidad.php");
?>
<?php
//Domicilio
if($_COOKIE['domicilio'] == 1){
echo("<input type='hidden' id='domicilioBreadcrumb' value='set'/>");
} else {
echo("<input type='hidden' id='domicilioBreadcrumb' value='not_set'/>");
}
//Recoger
if($_COOKIE['recoger'] == 1){
echo("<input type='hidden' id='recogerBreadcrumb' value='set'/>");
} else {
echo("<input type='hidden' id='recogerBreadcrumb' value='not_set'/>");
}
//Reservacion
if($_COOKIE['reservacion'] == 1){
echo("<input type='hidden' id='reservacionBreadcrumb' value='set'/>");
} else {
echo("<input type='hidden' id='reservacionBreadcrumb' value='not_set'/>");
}
?>
<div style="width:100%; text-align:center;"><img src="images/logoadmin.png" alt="" align="middle" /></div>
<div id="container">
<div id="box1" class="box">
<div class="titulo">Selecciona tu Ciudad:</div>
<div class="caja">
<select id="city">
<option value="San Pedro Garza García, Nuevo Leon">San Pedro Garza García</option>
<option value="Monterrey, Nuevo Leon">Monterrey</option>
</select><input id="tags" style="display:none" />
</div>
<img id="crossCiudad" src="images/cross2.gif" style="cursor:pointer" onclick="deleteCookie('puraCiudad')"/> <span id="ciudadBreadcrumb"></span>
<span class="btn1" id="ciudad">Continuar</span>
</div>
<div id="box2" class="box">
<div class="titulo">Selecciona el Tipo de Servicio:</div>
<div class="caja">
<input type="radio" id="domicilio" name="tipo" value="domicilio" class="selec"/><span class="servicios">A Domicilio</span>
<input type="radio" name="tipo" value="recoger" class="selec" onClick="setCookie('recoger', 'tipoDeServicio')"/><span class="servicios">Pasar a Recoger</span>
<input type="radio" name="tipo" value="reservar" class="selec" onClick="setCookie('reservar', 'tipoDeServicio')"/><span class="servicios">Reservar</span>
</div>
</div>
<div id="box3" class="box">
<div class="titulo">Selecciona tu Colonia:</div>
<div class="caja"><input id="tags2" value="Escribe tu colonia: Ej. Del Valle" onblur="if(this.value=='') this.value='Escribe tu colonia: Ej. Del Valle'" onfocus="if(this.value =='Escribe tu colonia: Ej. Del Valle' ) this.value=''" /></div>
<img id="crossColonia" src="images/cross2.gif" style="cursor:pointer" onclick="deleteCookie('ciudad')"/> <span id="coloniaBreadcrumb"></span>
<span class="coloniaButton" id="colonia">Continuar</span>
</div>
</div>
<div id="footer">
<span style="float: left;">Derechos Reservados Quierodecomer.com</span>
<span onclick="terminosCondicionesDialog()" style="cursor:pointer; text-decoration: underline;">El uso de este sitio web implica la aceptación de los términos y condiciones de quierodecomer.com</span>
<span style="float: right;">Login Restaurantes</span>
</div>
<div id="terminosCondiciones" title="Términos y Condiciones">
<?php echo $terminos; ?>
</div>
<script type="text/javascript">
/* Bookmark */
jQuery(document).ready(function(){
// add a "rel" attrib if Opera 7+
if(window.opera) {
if (jQuery("A.linkBookmark").attr("rel") != ""){ // don't overwrite the rel attrib if already set
jQuery("A.linkBookmark").attr("rel","sidebar");
}
}
jQuery("A.linkBookmark").click(function(event){
event.preventDefault(); // prevent the anchor tag from sending the user off to the link
var url = this.href;
var title = this.title;
if (window.sidebar) { // Mozilla Firefox Bookmark
window.sidebar.addPanel(title, url,"");
} else if( window.external ) { // IE Favorite
window.external.AddFavorite( url, title);
} else if(window.opera) { // Opera 7+
return false; // do nothing - the rel="sidebar" should do the trick
} else { // for Safari, Konq etc - browsers who do not support bookmarking scripts (that i could find anyway)
alert('Desafortunadamente, este navegador no soporta la petición ' + ' por favor, agrega esta página manualmente.');
}
});
$('.flexslider').flexslider();
});
</script>
</body>
</html>
I checked your JS console in IE7 mode and I got the following error :
SCRIPT1028: Expected identifier, string or number
testing.quierodecomer.com, line 215 character 2
So, try just to remove the last comma of your function :
$( "#terminosCondiciones" ).dialog({
autoOpen: false,
height: 350,
width: 450,
modal: true,
});

API google + php + MySql

I want to display the marker on the map but I can see only the first.
what is the problem?
while the marker did not show any
<?php
session_start();
//connessione al DB
include("dati_db.inc.php");
mysql_connect($host,$username,$password)or die("Connessione IMPOSSIBILE al DBMS. TIPO ERRORE:".mysql_error());
mysql_select_db($database)or die("IMPOSSIBILE selezionare il DataBase");
$idric=$_GET['id_ric']; //id richiesta
$sql = "SELECT * FROM richieste WHERE id=".$idric;
$dati=mysql_query($sql);
if (!$dati) {
echo "Query non eseguita correttamente sul DB(".$sql."): ".mysql_error();
exit;
}
$row=mysql_fetch_assoc($dati);
$luogo=$row['luogo'];
$indirizzo=$row['indirizzo'];
$descrizione=$row['descrizione'];
$oggetto=$row['oggetto'];
$indirizzogoogle=$luogo." , ".$indirizzo;
?>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalableo"/>
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<title>Google Maps API v3: geocoding</title>
<style type="text/css">
html, body { margin:0; padding:0; width:100%; height:100%; }
body { background:#FFFFFF; color:#000000; font-family:Arial, Helvetica, sans-serif; font-size:12px; line-height:150%; text-align:center;}
#map { width:100%; height:95%; }
input { width:250px; }
#tooltip { padding:10px; text-align:left; }
#tooltip p { padding:0; margin:0 0 5px 0; }
</style>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false&language=it"></script>
<script type="text/javascript" src="inc/jquery-1.7.2.js"></script>
<script type="text/javascript" src="inc/myjs.js"></script>
<script type="text/javascript">
var createMap = function() {
//indirizzo ricavato in precedenza del luogo dell'intervento
var address = "<?php echo ($indirizzogoogle);?>";
var geocoder = new google.maps.Geocoder();
geocoder.geocode( {'address': address}, function(results,status) {
if (status == google.maps.GeocoderStatus.OK) {
var options = {
zoom: 12,
center: results[0].geometry.location,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById('map'), options);
var marker = new google.maps.Marker(
{
position: results[0].geometry.location,
map: map,
title: 'punto di intervento'
}
);
var tooltip = '<div id="tooltip">'+
'<p>Indirizzo punto di intervento<br>'+
results[0].formatted_address+'</p>'+
'</div>';
var infowindow = new google.maps.InfoWindow({
content: tooltip
});
google.maps.event.addListener(marker, 'click', function() {
infowindow.open(map,marker);
});
sedi = new Array();
dim=0;
//popoli vettore
<?php
//recupero info di tutte le sedi
$query="SELECT * FROM utenti WHERE tipo=3";
$query_sedi=mysql_query($query);
//per ogni record creiamo un MARKER
$contcs=mysql_num_rows($query_sedi);
if($contcs > 0){
//se ci sono records mostriamo tutte le sedi in un ciclo
while($line = mysql_fetch_array($dati, MYSQL_ASSOC)){
//recupero alcune informazioni
$sede = $line['sede'];
echo ("cod_indirizzi($sede);\n");
}
}
?>
} else {
alert("Problema nella ricerca dell'indirizzo: " + status);
}
});
};
function cod_indirizzi(indirizzo){
geocoder.geocode({'address':indirizzo}, function(result, status){
map.setCenter(result[0].geometry.location);
var marker= new google.maps.Marker
({map:map,
position:result[0].geometry.location,
title: indirizzo});
});
}
window.onload = createMap;
</script>
</head>
<body>
<div id="map"></div>
</body>
</html>
the map obtained there is only a marker, and you should see 3
what is the error?
Here is a similar script i have done may this help u
use jquery 1.2.6
(function() {
window.onload = function()
{
var ttl=["place1","place2","place3"];
var options = {
zoom: 13,
center: new google.maps.LatLng(28.550000, 77.22496000000001),
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById('map'), options);
// Creating an array that will contain the coordinates
var places = [];
places.push(new google.maps.LatLng(28.550392878584265, 77.25169658660889));
places.push(new google.maps.LatLng(28.546396951091907 , 77.19741940498352));
places.push(new google.maps.LatLng(28.528748, 77.219663));
// Looping through the places array
for (var i = 0; i < places.length; i++)
{
// Adding the marker as usual
var marker = new google.maps.Marker({
position: places[i],
map: map,
title: ttl[i]
});
// Wrapping the event listener inside an anonymous function
// that we immediately invoke and passes the variable i to.
(function(i, marker) {
// Creating the event listener. It now has access to the values of
// i and marker as they were during its creation
google.maps.event.addListener(marker, 'mouseover', function() {
var infowindow = new google.maps.InfoWindow({
content: '<div style="overflow:hidden;">'+ttl[i]+'</div>'
});
infowindow.open(map, marker);
setTimeout(function () { infowindow.close(); }, 5000);
});
})(i, marker);
}
}
})();
HTML
<div id="map"></div>
CSS
#map {
width: 400px;
height: 400px;
border: 4px solid #ccc;
}

Categories