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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T08:44:37+00:00 2026-06-01T08:44:37+00:00

I created an object from PHP with json encode, but I am having difficulty

  • 0

I created an object from PHP with json encode, but I am having difficulty using the data to get the image width and height in the object.

This is how I created the objects:

    $get = mysql_query("SELECT x,y,img,bid FROM player WHERE uid='1'");
    while($row = mysql_fetch_assoc($get)){
        $data[$row['x']] = Array();
        $data[$row['x']][$row['y']][0] = $row['bid'];  // 1
        $data[$row['x']][$row['y']][1] = $row['img'];  // test.png
        }
$data1 = json_encode($data);    

See comments for test data used.

I assign this $data1 to variable sdata.

Now in my JavaScript I am trying to do this:

 imgwidth = sdata[i][j][1].width;
 imgheight = sdata[i][j][1].height;

But I get undefined, is there something I am missing out ?

  • 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-01T08:44:39+00:00Added an answer on June 1, 2026 at 8:44 am

    If I read this correctly, sdata[i][j][1] in JS will map to the string "test.png". That is, the JSON is encoding the filename of the image, not the image data itself. So sdata[i][j][1].width is asking for the width property of a string "test.png", which doesn’t exist.

    You’ll probably need to open the image on the server side (using ImageMagick or GD in PHP) and pull out the properties from there.

    Have a look at the getimagesize() function as a starting point.

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

Sidebar

Related Questions

I have created a JSON object in php using json_encode and am attempting to
I have created a json object from ruby with cobravsmongoose, however the attributes have
I want to return a json object from the onreadystatechange = function(){}, but I
I am using jQuery and JSON to pull data from a database. Each row
I have a list of objects like this (created from PHP then json encoded):
I'm trying to create a json object from MySQL results, but not getting the
I am using json_encode to create a JSON object from an array. They array
I'm having trouble parsing a json response. Its created via php and sent back
I am dealing with json data fetched from twitter API on PHP I normally
I'm having difficulty in retrieving values from a Json array. I have a Json

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.