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

  • SEARCH
  • Home
  • 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 8894413
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T23:29:22+00:00 2026-06-14T23:29:22+00:00

This seems simple, but I’m so new to this that I can’t get it

  • 0

This seems simple, but I’m so new to this that I can’t get it running – even after hours of reading tutorials and examples. I want my PHP to run a query, make an array of strings, and return the array to the jQuery ajax() that called for the data. The return array should be the strings stored in the database, and look like

citiesWithBoroughs = [
    "Dallas, Dallas County, Texas, United States",
    "Fort Worth, Tarrant County, Texas, United States",
    "El Paso, El Paso County, Texas, United States"
];

The query and array creation code are below. The query works in MySQL Workbench and returns the data I want. I have hard coded the country and state below to reduce sources of error while testing. I will replace them with “mysql_real_escape_string($countryAbbreviation)”, and so forth, when I get a controlled test working.

$return_arr=array();

$fetch = mysql_query("SELECT DISTINCT cityWithBoroughsGeonamed FROM places.boroughs
    WHERE countryAbbreviation='US'
    AND stateProvinceAbbreviation='NY'
    ") or die(mysql_error());
while ($row = mysql_fetch_array($fetch)){
    $return_arr[]=$row['cityWithBoroughsGeonamed'];
}
echo $return_arr;

Currently, Firebug tells me the key/value data goes to the PHP server, but I get an empty array returned. I’ve tried several things, but get nothing or an empty array – after lots of trials.

On the JavaScript side, here is the ajax function that requests the data, and gets the returned array.

citiesWithBoroughs = function (request, response){
$.ajax({
    url: "getCitiesWithBoroughs.php",
    data: {stateProvinceAbbreviation: $("#hiddenState").val(),
        countryAbbreviation: $('input[name=country]:checked').val()},
    type: "POST",
    dataType: "text",
    success: function (data){
        response;
    }
});

What has to change to get this right? Please be specific about code. I’m pretty new to this.

  • 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-14T23:29:23+00:00Added an answer on June 14, 2026 at 11:29 pm

    echo will output a string. $return_arr is an array of strings and echo $return_arr; will only output Array(). I would recommend using echo json_encode($return_arr); and handling the json encoded string in the success callback in the client side script.

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

Sidebar

Related Questions

This seems like it should be very simple but I can't get it to
This seems like something simple but I can't seem to get it to work.
This seems fairly simple but I can't get it to turn up on Google.
This seems really simple but I can't see that NSNumberFormatter has a function for
This seems simple but I can't figure it out. I receive post data in
this seems like a simple enough question but I can't seem to find a
This seems painfully simple, but I can't work out how to do it: I
This seems really simple but for whatever reason I can't access a few radio
This seems simple, but I haven't been able to find anything that does precisely
This seems like a simple problem but I can't seem to find the answer.

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.