title: How to use while loop in ajax response
body: <p>Here is my ajax</p>
  
  <pre><code>var vn = '*', dataString = 'vehicle_name='+ vn;
  
    $.ajax({
          type: "POST",
          url: "getDesc.php",
          data: dataString,
          dataType: "json",
          success: function(data){
              if(!data.error &amp;&amp; data.success) {
               var vn = data.vehicleName, st = data.serviceType, o = data.others, rn = data.ref_no, rd = data.ref_date, rt = data.ref_type;
               var myTable1 ='&lt;fieldset&gt;' +
                   '&lt;legend&gt;Dashboard&lt;/legend&gt;&lt;br&gt;' +
                      '&lt;table border="1" width="650"&gt;' +
                      '&lt;tr bgcolor=#c0c0c0&gt;' +
                              '&lt;td width=100 align="center"&gt;&lt;font face="helvetica"&gt;&lt;b&gt;Vehicle Name&lt;/b&gt;&lt;/font&gt;&lt;/td&gt;' +
                              '&lt;td width=80 align="center"&gt;&lt;font face="helvetica"&gt;&lt;b&gt;Service Type&lt;/b&gt;&lt;/font&gt;&lt;/td&gt;' +
                              '&lt;td width=80 align="center"&gt;&lt;font face="helvetica"&gt;&lt;b&gt;Others&lt;/b&gt;&lt;/font&gt;&lt;/td&gt;' +
                              '&lt;td width=100 align="center"&gt;&lt;font face="helvetica"&gt;&lt;b&gt;Reference No.&lt;/b&gt;&lt;/font&gt;&lt;/td&gt;' +
                              '&lt;td width=80 align="center"&gt;&lt;font face="helvetica"&gt;&lt;b&gt;Reference Date&lt;/b&gt;&lt;/font&gt;&lt;/td&gt;' +
                              '&lt;td width=80 align="center"&gt;&lt;font face="helvetica"&gt;&lt;b&gt;Reference Type&lt;/b&gt;&lt;/font&gt;&lt;/td&gt;' +
                          '&lt;/tr&gt;' +
  
                          '&lt;tr bgcolor=#c0c0c0&gt;' +
                              '&lt;td align=center&gt;'+vn+'&lt;/td&gt;' +
                              '&lt;td align=center&gt;'+st+'&lt;/td&gt;' +
                              '&lt;td align=center&gt;'+o+'&lt;/td&gt;' +
                              '&lt;td align=center&gt;'+rn+'&lt;/td&gt;' +
                              '&lt;td align=center&gt;'+rd+'&lt;/td&gt;' +
                              '&lt;td align=center&gt;'+rt+'&lt;/td&gt;' +
                          '&lt;/tr&gt;' +
                      '&lt;/table&gt;' +
                   '&lt;/fieldset&gt;';
                    $('#tabs-4').append(myTable1);
  
              } else {
                  alert(data.errorMsg);
              }
          }
          });
  </code></pre>
  
  <p>Here is my PHP</p>
  
  <pre><code>&lt;?PHP
  include("db.classes.php");
  $g = new DB();
  $g-&gt;connection();
  
          if($_POST)
              {
                  $vehicleName = $g-&gt;clean($_POST["vehicle_name"],1);
  
                  $g-&gt;getAllDesc($vehicleName);
              }
  $g-&gt;close();
   ?&gt;
  </code></pre>
  
  <p>Here is my db.classes</p>
  
  <pre><code>public function getAllDesc($vehicleName)
      {
          header('Content-type: application/json');
          $sql = "select vehicle_name, service_type, others, ref_no, ref_date, ref_type from vehicle_services";
  
          $result = mysql_query($sql) or die(json_encode(array('error' =&gt; 0,'errorMsg' =&gt; "MySQL query failed.")));
  
          while($row = mysql_fetch_array($result))
          {
  
              $output[] = array(
                  'success' =&gt; 1,
                  'vehicleName' =&gt; $row["vehicle_name"],
                  'serviceType' =&gt; $row["service_type"],
                  'others' =&gt; $row["others"],
                  'ref_no' =&gt; $row["ref_no"],
                  'ref_date' =&gt; $row["ref_date"],
                  'ref_type' =&gt; $row["ref_type"]                 
                  );
  
                  echo json_encode($output);
          }
  
      }
  </code></pre>
  
  <p>And here is the response I get</p>
  
  <blockquote>
    <p>[{"success":1,"vehicleName":"JHE699","serviceType":"CHANGE
    TIRE","others":"","ref_no":"14010001","ref_date":"2014-04-10","ref_type":"PRRIAR"}][{"success":1,"vehicleName":"JHE699","serviceType":"CHANGE
    TIRE","others":"","ref_no":"14010001","ref_date":"2014-04-10","ref_type":"PRRIAR"},{"success":1,"vehicleName":"TOYOTA
    86","serviceType":"TRUCK","others":"","ref_no":"1","ref_date":"2014-05-07","ref_type":"RR"}]</p>
  </blockquote>
  
  <p>My first row gets duplicated and the table does not display. How do i pass the array so that my table would display?</p>