JSON encode MySQL results then read using jQuery

Posted by silentw on Stack Overflow See other posts from Stack Overflow or by silentw
Published on 2012-06-20T08:54:58Z Indexed on 2012/06/20 9:16 UTC
Read the original article Hit count: 322

Filed under:
|
|

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)

© Stack Overflow or respective owner

Related posts about php

Related posts about jQuery