June 28, 2012

add data dynamically from JSON array to HTML table using JQuery

Question by nag

php file:

$sql=mysql_query("select first,last,email,city from userdata"); 

json output:


html code:


        $("#userdata tbody").html("");
                    var tblRow =
                    $(tblRow).appendTo("#userdata tbody");

i was displayed data from database using php in JSON format..i want to insert this data into table format in html page, i created table in html also..i tried using above script but it didn’t fetch any data..plz help me plz..

Answer by Starx

Your PHP is printing the array in an incremented format.

Make the following changes:


Next, there is no userdata in the output, so just use data.

Author: Nabin Nepal (Starx)

Hello, I am Nabin Nepal and you can call me Starx. This is my blog where write about my life and my involvements. I am a Software Developer, A Cyclist and a Realist. I hope you will find my blog interesting. Follow me on Google+


Please fill the form - I will response as fast as I can!