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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T06:14:54+00:00 2026-05-30T06:14:54+00:00

Here is my code: $result = mysql_query(SELECT * FROM Product_Characteristics); $charact_array = array(); while($row

  • 0

Here is my code:

    $result = mysql_query("SELECT * FROM Product_Characteristics");

    $charact_array = array();

    while($row = mysql_fetch_array($result)) {
        $charact_array[$row['PC_ID']] = $row['Title'];

    }

    $JSON_char = json_encode($charact_array);

    echo $JSON_char;

The echoed response is something like this:

{"1":"product1","2":"product2","3":"product3","4":"product4"}   

I am not sure how to access these values using the eval function in javascript once this data is returned…

Typically, using the eval function I can obtain the values of something like this:

{
    "ptypes": {
        "aptype": [
            {
                "id": "1",
                "title": "product1"
            },
            {
                "id": "2",
                "title": "product2"
            }
        ]
    }
}

Using some code like this:

var JSONobject = eval('(' + msg + ')'); //msg is the JSON response from above

alert(JSONobject.ptypes.aptype.title[0]) // product1

I basically need to be able to access the values within the JSON (which I have encoded above from a PHP associative array) and loop through them.

If this is not possible, or if it is better to encapsulate my JSON data within the structures “ptypes” and “aptype” (which seems not necessary), I appreciate any advice.

  • 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-30T06:14:55+00:00Added an answer on May 30, 2026 at 6:14 am

    If you are receiving an actual string, you can parse it using

    var jsonObj = JSON.parse(msg);
    alert(jsonObj[1]);
    

    What you really should be doing though is returning the correct content type

    // at the end of your PHP script
    header('Content-type: application/json');
    echo $JSON_CHAR;
    exit;
    

    Then, you can use something like jQuery’s getJSON() function

    $.getJSON('some/url.php', function(data) {
        alert(data[1]);
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Some code here, I want store mysql query result into an array with php,
Here is my code: records_hash = records[:id].inject({}) { |result,h| if result.has_key?(h) result[h] += 1
I'm using cocoa JSON framework http://code.google.com/p/json-framework/ Here is the result of an JSON output
Here is code from MSDN . I don't understand why the work isn't just
How do I highlight keywords in search result? Here's an example of my code:
I got a problem in querying an information in mySQL, here's the code: SELECT
I'm trying to query a single result from two tables in my database. Here
here is my current line of code: $(<li>).text($(this).text()).appendTo(#theList); Which results in <ul id=theList> <li>blah</li>
Ok the error is showing up somewhere in this here code if($error==false) { $query
Here a code to demonstrate an annoying problem: class A { public: A(): m_b(1),

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.