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 6802651
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T19:14:56+00:00 2026-05-26T19:14:56+00:00

I am currently working on a php/javascript project which retrieves information from a database

  • 0

I am currently working on a php/javascript project which retrieves information from a database and json encodes the data. It is supposed to show the values from the database inside a combo box on the web page.

In the PHP script that encodes the mysql data I have the following code:

$query = "SELECT pla_platformName as `platform` FROM platforms";

    $result = mysql_query($query);

    if ($result)
    {       
        while ($myrow = mysql_fetch_array($result))
        {
            $output[] = $myrow;                     
        }

        print json_encode($output);
        die();
    }

In the javascript code I have the following:

<script>
        $(document).ready(function()
        {
            getPlatforms();
            function getPlatforms()
            {
                $.post("phpHandler/get-platforms.php", function(json)
                    {
                        alert(json);    
                        alert(json.platform);
                    }
                );
            }
        });
    </script>

I have alert(json); which shows the entire json data which looks like the following:

[{“0″:”hello”,”platform”:”hello”},{“0″:”android”,”platform”:”world”}]

The next alert(json.platform) I am expecting it to show either hello or world or both but on this line it keeps on saying undefined. Why isn’t this working and how do I get a specific platform, i.e. either hello, or world.

Thanks for any help you can provide.

  • 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-05-26T19:14:56+00:00Added an answer on May 26, 2026 at 7:14 pm

    You need to first convert your JSON string into an object

    var data = $.parseJSON(json);
    

    In this case, the object returned is an array. Try

    alert(data[0].platform);
    

    You can skip the first step if you set the dataType option to json in your ajax call.

    $.post("phpHandler/get-platforms.php", function(data) {
         alert(data[0].platform);
      }, 
      'json'
     );
    

    See jQuery.post() documentation

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

Sidebar

Related Questions

I'm currently working on a PHP application that uses a MySQL database for its
In the project my team is currently working on, we're modifying a commercial PHP
So I'm a coder, I do PHP, JavaScript, and Objective-C. I'm currently working on
Im working on a project currently and really using javascript, Jquery / AJAX heavily
I am currently working on an html and php project. What I want to
I am currently working on a PHP application that puts me in the desperate
I'm currently working on an OO PHP application. I have a class called validation
I am currently working on a small sponsorship application(PHP/MySql) for my personal blog, and
I'm currently working on a website in PHP, and I'm wondering what the best
I am currently working on a web application that uses PHP and MySQL, but

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.