title: get the data from database with ajax
body: <p>i want to get the data from database through ajax  but its gives me only one record not other but i want all the records from database i have search too much to understand the problem 
  but can't get that </p>
  
  <p><a href="https://i.stack.imgur.com/u1E1N.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/u1E1N.jpg" alt="enter image description here"></a>   </p>
  
  <p>that is database image</p>
  
  <p>php code
  
  
  <pre><code> //-------------------------------------------------------------------------- 
    // Example php script for fetching data from mysql database
    //--------------------------------------------------------------------------
    $host = "localhost";
    $user = "root";
    $pass = "";
  
    $databaseName = "search";
    $tableName = "ajax01";
  
    //--------------------------------------------------------------------------
    // 1) Connect to mysql database
    //--------------------------------------------------------------------------
    include 'DB.php';
    $con = mysql_connect($host,$user,$pass);
    $dbs = mysql_select_db($databaseName, $con);
  
    //--------------------------------------------------------------------------
    // 2) Query database for data
    //--------------------------------------------------------------------------
    $result = mysql_query("SELECT * FROM $tableName");          //query
    $array = mysql_fetch_row($result);                          //fetch result    
  
    //--------------------------------------------------------------------------
    // 3) echo result as json 
   //--------------------------------------------------------------------------
    echo json_encode($array);
  
  ?&gt; 
  </code></pre>
  
  <p>html
      
        
             
       
       </p>
  
  <pre><code>  &lt;!-------------------------------------------------------------------------
    1) Create some html content that can be accessed by jquery
   --------------------------------------------------------------------------&gt;
    &lt;h2&gt;&lt;/h2&gt;
  
  
    &lt;script id="source" language="javascript" type="text/javascript"&gt;
  
    $(function () 
    {
  //-----------------------------------------------------------------------
  // 2) Send a http request with AJAX http://api.jquery.com/jQuery.ajax/
  //-----------------------------------------------------------------------
  $.ajax({                                      
    url: 'api.php',                  //the script to call to get data          
    data: "",                        //you can insert url argumnets here to    pass to api.php
                                     //for example "id=5&amp;parent=6"
    dataType: 'json',                //data format      
    success: function(data)          //on recieve of reply
    {
     // var id = data[0];              //get id
    //  var vname = data[1];           //get name
      //--------------------------------------------------------------------
      // 3) Update html content
      //--------------------------------------------------------------------
      $('#output').html("&lt;b&gt;id: &lt;/b&gt;"+id+"&lt;b&gt; name: &lt;/b&gt;"+name); //Set output     element html
      //recommend reading up on jquery selectors they are awesome 
      // http://api.jquery.com/category/selectors/
    } 
  });
   }); 
  
    &lt;/script&gt;
   &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>