title: Exporting html table created by PHP into Excel
body: <p>I have a html table created by PHP using mysql and I used "table to excel" JQUERY method to export it but the problem that I ran into is printed variables from Mysql into this table are not exporting to excel I mean when I export the table to Excel I can see just the headers or column names and all html variables not php variables </p>
  
  <p>JQUERY script : </p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
      var tableToExcel = (function() {
        var uri = 'data:application/vnd.ms-excel;base64,'
          , template = '&lt;html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40"&gt;&lt;head&gt;&lt;!--[if gte mso 9]&gt;&lt;xml&gt;&lt;x:ExcelWorkbook&gt;&lt;x:ExcelWorksheets&gt;&lt;x:ExcelWorksheet&gt;&lt;x:Name&gt;{worksheet}&lt;/x:Name&gt;&lt;x:WorksheetOptions&gt;&lt;x:DisplayGridlines/&gt;&lt;/x:WorksheetOptions&gt;&lt;/x:ExcelWorksheet&gt;&lt;/x:ExcelWorksheets&gt;&lt;/x:ExcelWorkbook&gt;&lt;/xml&gt;&lt;![endif]--&gt;&lt;meta http-equiv="content-type" content="text/plain; charset=UTF-8"/&gt;&lt;/head&gt;&lt;body&gt;&lt;table&gt;{table}&lt;/table&gt;&lt;/body&gt;&lt;/html&gt;'
          , base64 = function(s) { return window.btoa(unescape(encodeURIComponent(s))) }
          , format = function(s, c) { return s.replace(/{(\w+)}/g, function(m, p) { return c[p]; }) }
        return function(table, name) {
          if (!table.nodeType) table = document.getElementById(table)
          var ctx = {worksheet: name || 'Worksheet', table: table.innerHTML}
          window.location.href = uri + base64(format(template, ctx))
        }
      })()
  &lt;/script&gt;
  </code></pre>
  
  <p>html table created by php :</p>
  
  <pre><code> &lt;?php
          $tbl_name="form_0"; // Table name   
          $query = mysqli_query($con,"SELECT * FROM `{$tbl_name}` WHERE `uni_id`='{$_SESSION["uni_id"]}'   ");
          $count=mysqli_num_rows($query);
  
                  ?&gt;  
                      &lt;table class='styled-table' id="testTable" cellspacing='0' border='1' rules="groups"&gt;
                          &lt;thead&gt;
                              &lt;tr&gt;
                                  &lt;th  scope='col' style='font-size:13px;'&gt;sample 1&lt;/th&gt;
                                  &lt;th  scope='col' style='font-size:13px;'&gt;sample 2&lt;/th&gt;
                                  &lt;th  scope='col' style='font-size:13px;'&gt;sample 3&lt;/th&gt;
                                  &lt;th  scope='col' style='font-size:13px;'&gt;sample 4&lt;/th&gt;
                                  &lt;th  scope='col' style='font-size:13px;'&gt;sample 5 گواهی&lt;/th&gt;
                              &lt;/tr&gt;
                          &lt;/thead&gt;
  
                  &lt;?php   while($row = mysqli_fetch_assoc($query)){ ?&gt;     
  
                          &lt;tbody&gt;
                              &lt;tr&gt;
                                  &lt;td align='center'&gt;&lt;input  class='styled-input' style=' padding: 5px; width: 100px;margin-right:2px;margin-left:2px;' type='text' name='morabi' id='morabi' value= "&lt;?php echo $row['morabi']; ?&gt;" &gt;&lt;/td&gt;
                                  &lt;td align='center'&gt;&lt;input  class='styled-input' style=' padding: 5px; width: 100px;margin-right:2px;margin-left:2px;' type='text' name='ostadyar' id='ostadyar' value= "&lt;?php echo $row['ostadyar']; ?&gt;" &gt;&lt;/td&gt;
                                  &lt;td align='center'&gt;&lt;input  class='styled-input' style=' padding: 5px; width: 100px;margin-right:2px;margin-left:2px;' type='text' name='daneshyar' id='daneshyar' value= "&lt;?php echo $row['daneshyar']; ?&gt;" &gt;&lt;/td&gt;
                                  &lt;td align='center'&gt;&lt;input  class='styled-input' style=' padding: 5px; width: 100px;margin-right:2px;margin-left:2px;' type='text' name='ostad' id='ostad' value= "&lt;?php echo $row['ostad']; ?&gt;" &gt;&lt;/td&gt;
                                  &lt;td align='center'&gt;&lt;a      class='styled-input' style=' padding: 7px; margin-right:2px;margin-left:2px;color:#008AB8;' href="&lt;?php echo '../../../../uploads/form_0/'.$row['govahi']; ?&gt;"  target="_blank")"&gt;view&lt;/a&gt;&lt;/td&gt;
                              &lt;/tr&gt;
                          &lt;/tbody&gt;
                  &lt;?php } ?&gt;                              
  
                      &lt;/table&gt;
                      &lt;div class='cleaner h20'&gt;&lt;/div&gt;
  
                      &lt;input class='styled-input_2' style="width:105px;" type="button" onclick="tableToExcel('testTable', 'W3C Example Table')" value="export to excel" /&gt;
  
                      &lt;div class='cleaner h20'&gt;&lt;/div&gt;
  </code></pre>