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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T08:02:18+00:00 2026-06-18T08:02:18+00:00

I want to create a json files from a php functions (or directly from

  • 0

I want to create a json files from a php functions (or directly from my BDD).

I have a php function that write in my database sql

This is my function that write in my database (it’s magento, but it works) :

$data = array('image'=>$my_upload->file_copy,'shopid'=>$customerid,'newsid'=>1);
$model = Mage::getModel('newsimagestable/newsimagestable')->setData($data);

Md table db_activity

shopid      newsid          imgid                    image
   7           1              1                     1.jpg
   7           1              2                     2.jpg
   7           1              3                     3.jpg

And know I convert this to Json with this function :

$actArray = array();
    $activityAll = Mage::helper(eventdemo)->getactivitytest(7); //get my table db_activity

        foreach ($activityAll as $data){                
            array_push($actArray, "images:".$data->getData('image'),"thumb:".$data->getData('image'));              
        };

    file_put_contents('data.json',  stripslashes(json_encode($actArray)));

And I can only get the json files in this format :

["images:1.jpg","thumb:1_m.jpg","images:2.jpg","thumb:2_m.jpg","images:3.jpg","thumb:3_m.jpg"]

But I want to have this format (so an array with multiple entry I think) :

[
{ "thumb": "image1_m.jpg", "image": "image1.jpg" },
{ "thumb": "image2_m.jpg", "image": "image2.jpg" }  ]

Is that possible ?

Thanks

  • 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-18T08:02:19+00:00Added an answer on June 18, 2026 at 8:02 am

    Instead of

    foreach ($activityAll as $data){                
                array_push($actArray, "images:".$data->getData('image'),"thumb:".$data->getData('image'));              
            };
    

    you should do

    foreach ($activityAll as $data){                
                array_push($actArray, array("images" => $data->getData('image'), "thumb" => $data->getData('image')));              
            };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i want create a custom json data from the mssql 2008 results so that
I want to create a JSON object from my MySQL results with PHP so
This the model that I want to create using json file Ext.define('Users', { extend:
I want to create JSON object using tow query in PHP , Then retrieve
Hi I want to create a JSON array. I have tried using: JSONArray jArray
I have a php file that creates a json output. my problem is that
I have a JSON file that was converted from a csv and is too
I want to be able to dynamically create ViewControllers based on a JSON file.
I want to create a .NET webservice using C# with JSON. but I've error
i want create multiple search where statement $where_search is a multiple condition from post

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.