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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T23:26:03+00:00 2026-06-13T23:26:03+00:00

I want to export CSV file to JSON file,require is read value at recommend

  • 0

I want to export CSV file to JSON file,require is read value at recommend field and write to JSON file. Exapmle : IN row 1,recomnend =2 will read the row that id=2 and print to JSON file that values : id,product_id,title.

$json = array();

        $json['id'] = $row['id'];
        $json['product_id'] = $row['product_id'];
        $json['title'] = $row['title'];
        $json['outline'] = $row['outline'];
        $recom[] = $json;  
print json_encode($recom);

http://ns0.upanh.com/b6.s33.d3/3a3ebb93a87c5703f673b399d5613ec2_50639320.untitled.png

  • 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-13T23:26:04+00:00Added an answer on June 13, 2026 at 11:26 pm

    I don’t know of a different way of doing it, but the following will work. Using this method means that you have to use the column index, not the name of it. This shouldn’t be a problem if you know the column index of the values you need, but I just thought I would mention:

    $fp = fopen('test.csv','r') or die("**! can't open file\n\n");
    while($csv_line = fgetcsv($fp,1024)) {
        $id = $csv_line[0];
        $product_id = $csv_line[1];
        $title = $csv_line[2];
        $outline = $csv_line[3];        
    }
    fclose($fp) or die("**! can't close file\n\n");
    

    Now, because you will have multiple rows, I would recommend the following to save them into one JSON object:

    $fp = fopen('test.csv','r') or die("**! can't open file\n\n");
    $i = 0;
    while($csv_line = fgetcsv($fp,1024)) {
        $i++;
        $json['json_'.$i]['id'] = $csv_line[0];
        $json['json_'.$i]['product_id'] = $csv_line[1];
        $json['json_'.$i]['title'] = $csv_line[2];
        $json['json_'.$i]['outline'] = $csv_line[3];        
    }
    $json['total_lines'] = $i;
    print json_encode($json);
    fclose($fp) or die("**! can't close file\n\n");
    

    With this method, you can save each row as a sub-JSON Object, making it possible to pull the total number and parse through the objects to pull out the rows.

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

Sidebar

Related Questions

I want to export the database to CSV file and read in MatLab. I
I want to export TVP (Type of DataTable) to .csv file, or .xls, but
I want to export data from my application into a csv file. I found
I have a gridview that I want to export to a .csv file. I
In my app, I want to export a SQLite database file to CSV file..
I want to export my contacts from gmail into a csv file.. Then upload
I want to export query result in csv file. I used query select *
i want to export datas in csv file(csv file is a type as the
I have a export script that export items to a csv file. I want
I have a simple report that I want to export to a CSV file.

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.