Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8707245
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T03:49:22+00:00 2026-06-13T03:49:22+00:00

Hi all I need to return a results from PHP to Javascript. Here is

  • 0

Hi all I need to return a results from PHP to Javascript.

Here is my PHP code and I need to form it to be used in javascript.

$result = dbMySql::Exec('SELECT Latitude,Longitude FROM data');
while ($row = mysqli_fetch_assoc($result))
   $coordinates[] = 'new google.maps.LatLng(' . $row['Latitude'] . ', ' . $row['Longitude'] . ')';

I need to return an array $coordinates and implode it like this but with Javascript:

var flightPlanCoordinates = [<?php echo implode(',', $coordinates) ?>];

This is how I started in javascript:

$.ajax({
        type: 'POST',
        url: 'history.php',
        data: {'query': url},
       });
var flightPlanCoordinates = [<?php echo implode(',', $coordinates) ?>];

And I need to fill this variable with returned data and with the JOIN or some other function that does same thing as implode in PHP.

EDIT:

This is my ajax code:

$.ajax({
                  type: 'POST',
                  url: 'history.php',
                  data: {
                  'id_user':$('#select-choice-user').val(),
                  'reg_id':$('#select-choice-reg').val(),
                  'd_year1':$('#select-choice-year1').val(),
                  'd_month1':   $('#select-choice-month1').val(),
                  'd_day1':$('#select-choice-day1').val(),
                  'd_year2':$('#select-choice-year2').val(),
                  'd_month2':   $('#select-choice-month2').val(),
                  'd_day2':$('#select-choice-day2').val()
                  },
                  success: function(data)//callback to be executed when the response has been received
                        {

                            for (var i=0;i<data.length;i++)
                            {
                                flightPlanCoordinates[i] = new google.maps.LatLng(data[i].x,data[i].y);
                            }
                        }
                });

These are returned values in JSON format:

[
    {
        "x": "46.5564266666667",
        "y": "15.6467166666667"
    },
    {
        "x": "46.5566583333333",
        "y": "15.6465533333333"
    },
    {
        "x": "46.5567416666667",
        "y": "15.6465566666667"
    },
    {
        "x": "46.556745",
        "y": "15.646555"
    },
    {
        "x": "46.5567366666667",
        "y": "15.6465766666667"
    },
    {
        "x": "46.55675",
        "y": "15.6465933333333"
    },
    {
        "x": "46.55677",
        "y": "15.6466116666667"
    },
    {
        "x": "46.5567766666667",
        "y": "15.6466183333333"
    },
    {
        "x": "46.5567783333333",
        "y": "15.64662"
    },
    {
        "x": "46.5567583333333",
        "y": "15.6466066666667"
    },
    {
        "x": "46.556725",
        "y": "15.6465966666667"
    },
    {
        "x": "46.5566983333333",
        "y": "15.6465983333333"
    }
]

I’ve checked in JSON validator and format is valid. So I have no idea what could be wrong.

I will put PHP code just to make sure that it is written as it should be:

$result = dbMySql::Exec($query);
while ($row = mysql_fetch_assoc($result))
{
    $coordinates[] = array('x' => $row['Latitude'], 'y' => $row['Longitude']);
}
echo json_encode($coordinates);//send as JSON object

Type of the errors that I get in the console:

Uncaught Error: Invalid value for constructor parameter 0: undefined   
Uncaught TypeError: Cannot set property '0' of undefined
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T03:49:23+00:00Added an answer on June 13, 2026 at 3:49 am

    Ok, reading the comments, it appears to be the case that var flightPlanCoordinates should be assigned the return value of an ajax call. In that case:

    var flightPlanCoordinates = [];
    $.ajax({type: 'POST',
            url: 'history.php',
            data: {'query': url},
            success: function(data)//callback to be executed when the response has been received
            {
                for (var i=0;i<data.length;i++)
                {
                    flightPlanCoordinates[i] = new google.maps.LatLng(data[i].x,data[i].y);
                }
            }
        });
    

    And, to avoid eval, just return the data like so:

    while ($row = mysqli_fetch_assoc($result))
    {
        $coordinates[] = array('x' => $row['Latitude'], 'y' => $row['Longitude']);
    }
    echo json_encode($coordinates);//send as JSON object
    

    That should do the trick

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a variable called $result which should store all the results from my
In ASP.NET Application. I need to return string (which contains all necessary html tags)
Here is my issue. I am trying to call a page: foo.php?docID=bar and return
<?php include 'includes/config.php'; function do_curl($start_index, $stop_index) { // Do query here to get all
Noob at javascript etc. here. I’m a php/core Java programmer tasked with maintaining a
I have a system which will return all users from the database and order
I'm writing a function that will return database results. I need it to return
I need to write a query that returns all object less that or equal
In a shell-script (or Perl) I need a subroutine that returns for all my
I'm struggling with a css selector. I need a css rule that returns all

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.