JQuery table in php
<p>How i could get work a php file with sql queries and JQuery together?. The final object is to get multiple tables as the <a href="http://jsfiddle.net/96Lhog5g/3/" rel="nofollow noreferrer">http://jsfiddle.net/96Lhog5g/3/</a> demo but using the php code below.Something like this but in php<a href="https://i.stack.imgur.com/yuX7B.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/yuX7B.png" alt="enter image description here"></a> 
-Php code: </p>

<pre><code>    &lt;?php
         $dbconn = pg_connect(
         $sql1 = "SELECT unaccent(name) from base1;";
         $sql2 = "select id from servic;";

         $name = pg_query($sql1);
         $ident= pg_query($sql2);
         $data1 = pg_fetch_all_columns($name);
         $data2 = pg_fetch_all_columns($ident);
         $count = count($data1);
            echo '&lt;table id="mainTable" border="1" style="width:450px;position:relative;left:80px;"&gt;'; 
                echo '&lt;tr &gt;';   
                echo '&lt;th style="background: #3498db; width:5px;text-align: center ;font-size:12px;font-family:Arial Narrow"&gt;ID&lt;/th&gt;';
                echo '&lt;th style="background: #3498db; width:10px;text-align: center ;font-size:12px;font-family:Arial Narrow"&gt;NAME&lt;/th&gt;';   
                echo '&lt;/tr&gt;';
                for ($i = 0; $i &lt; $count; $i++) {
                    $data1[$i];
                    $data2[$i];
                echo '&lt;tr &gt;&lt;td&gt;' . $data2[$i] . '&lt;/td&gt;';
                echo '&lt;td&gt;' . $data1[$i] . '&lt;/td&gt;&lt;/tr&gt;';    
                }
            echo '&lt;/table&gt;';
        pg_free_result($name);
        pg_close($dbconn);
    ?&gt;
</code></pre>

<ul>
<li><p>JQuery code:</p>

<pre><code>var $main = $('#mainTable'),

$head = $main.find('tr:first'),

$extraRows = $main.find('tr:gt(2)');

for( var i = 0; i &lt; $extraRows.length; i = i+4){
    $('&lt;table&gt;').append($head.clone(),  
    $extraRows.slice(i,i+2)).appendTo($main.parent()); 
}
</code></pre></li>
</ul>

<p>,from <a href="http://jsfiddle.net/96Lhog5g/3/" rel="nofollow noreferrer">http://jsfiddle.net/96Lhog5g/3/</a>. I have tried adapt this code to php but my knowledge about it are limited.
Thanks in advance.</p>