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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T23:07:34+00:00 2026-06-05T23:07:34+00:00

I have a database table with some rows that I want to fetch using

  • 0

I have a database table with some rows that I want to fetch using PHP and then encode them using JSON.

Currently, my database structure is the following:

idcomponente | quantidade

After fetching the values in PHP, I want to know how can I encode them using JSON (with multiple rows, using the same names) so I can read them using jQuery.post().

$.post('test.php',{id:id},function(data){
    //READ data HERE
});

Thanks in advance

Edit:

So far, I made this:

$.post('edit/producomponentes.php',{id:id},function(data){
    console.log(data);
});

Logs this:

[Object { componente="1", quantidade="2"}, Object { componente="3", quantidade="3"}]

Now how can I go through each row and fetch their properties? (data.componente, data.quantidade)

  • 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-05T23:07:35+00:00Added an answer on June 5, 2026 at 11:07 pm

    Here I try to give you some idea.

    Make associative array in PHP using key => value pair like

    $data = array('id' => 1, 'quat' => 10, 'id' => 2, 'quat' => 20)
    

    and then send it as json_encode() like

    header('Content-type: application/json');  // don't miss it
    echo json_encode(array('data' => $data));
    

    In jQuery

    $.post('edit/producomponentes.php',{id:id},function(response){
        //READ data HERE.
        console.log(response.data); // you will get a json Object
    }, 'json');
         ^-------- set dataType as json, then you don't any extra parse effort
    

    According to edit

     $.post('edit/producomponentes.php',{id:id},function(data){
            $.each(data, function(index, value) {
               console.log(value.componente);
               console.log(value.quantidade);
            });
        }, 'json');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some code that grabs some rows from a table and I want
In a nutshell: I have some database table data that I want to populate
I have some code to update a database table that looks like try {
I have a table in database that is having some fields one of which
I have a table within my database that has many records, some records share
I have a table generated from some PHP code that lists a SMALL amount
Suppose I have this database table (some sample code below) that stores the relationship
In a MySQL database table, I want to UPDATE some rows with the results
I have a table that has some content in it. Not all rows has
I have a table that get its rows from a MYSQL database <table id=table1>

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.