Click here to Skip to main content
13,832,420 members
Rate this:
Please Sign up or sign in to vote.
See more:
I want to retrieve multiple rows from my mysql database with Ajax, Javascipt, PHP but I seem to be running into problem. My codes are below:




$query = "SELECT fname,sname FROM info WHERE userid = '$user_id' ";
  $result = mysql_query($query);
  while ($row = mysql_fetch_array($result)){

    $fname= $row['fname'];
    $sname= $row['sname'];

    $results[] = array("sname" => $fname, "fname" => $sname);



    // Don't worry about this

      url: 'list.php',                  //the script to call to get data          
      data: "?user=5778", //5778 is a sample data to pass to list.php
      dataType: 'json',                //data format      
      success: function(data)          //on recieve of reply

		 var html, comment;
            for(var i = 0; i < data.length; i++) {
                comment = data[i];
                html += '<td>'+ + '</td><td>' + comment.vname + '</td><td> details</td>'


Please I need help. I want it to automatically generate a table on the page that is, each result on a new row. thanks

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

If you want a record on each row, so add the <tr> element:
html += '<tr><td>'+ + '</td><td>' + comment.vname + '</td><td> details</td></tr>'

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Cookies | Terms of Service
Web02 | 2.8.190114.1 | Last Updated 3 Jul 2013
Copyright © CodeProject, 1999-2019
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100