Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP- need first 3 json data in the first table and all data in second table
    primarykey
    data
    text
    <p>I am a beginner in PHP programing.i have a code and i need to get the first 3 datas in the first table and all the datas in the next table.the data is coming from db as json.</p> <p>The following is my php file</p> <pre><code>&lt;?php $host = "localhost"; $user = "root"; $pass = ""; $database = "TMS_Sample"; $linkID = mysql_connect($host, $user, $pass) or die("Could not connect to host."); mysql_select_db($database, $linkID) or die("Could not find database."); $result = mysql_query("SELECT * FROM Completed_Training"); while ($row = mysql_fetch_assoc($result)) { $array[] = $row; } echo json_encode($array); ?&gt; </code></pre> <p>I get the following json as result:</p> <pre><code>[{"Date":"2012-12- 04","Topic":"Collections","Trainer":"Prabhakaran.G","Status":"Invitation Sent"},{"Date":"2012-12-12","Topic":"Collections","Trainer":"Prabhakaran.G","Status":"Invitation Sent"},{"Date":"2012-12-07","Topic":"ffb","Trainer":"vcvxcv","Status":"cvxcv"},{"Date":"2012-12-08","Topic":"xcv","Trainer":"cvxcv","Status":"vxcv"},{"Date":"2012-12-09","Topic":"cvxcv","Trainer":"cvxcv","Status":"cvxcvxc"},{"Date":"2012-12-10","Topic":"xcv","Trainer":"vxcvxc","Status":"vxcv"},{"Date":"2012-12-11","Topic":"vv","Trainer":"vv","Status":"vxcv"},{"Date":"2012-12-12","Topic":"vv","Trainer":"vcv","Status":"cvxcv"},{"Date":"2012-12-13","Topic":"vv","Trainer":"cvxcv","Status":"cvv"},{"Date":"2012-12-14","Topic":"vxcv","Trainer":"vccv","Status":"xcvcv"},{"Date":"2012-12-14","Topic":"vcxvxc","Trainer":"cvxcv","Status":"cvxcv"},{"Date":"2012-12-15","Topic":"cvxcv","Trainer":"xcvxcv","Status":"xcvxcv"},{"Date":"2012-12-16","Topic":"sdasd","Trainer":"sdasd","Status":"dscxzc"},{"Date":"2012-12-16","Topic":"scxzcxzc","Trainer":"sdfscxzc","Status":"sadffcvzxc"},{"Date":"2012-12-17","Topic":"fxzcvxzc","Trainer":"zcvxzcz","Status":"xzcxzcxzcxz"},{"Date":"2012-12-18","Topic":"xzceafsdfv","Trainer":"vxvxv","Status":"xgsdfgvsd"},{"Date":"2012-12-12","Topic":"xcdvxvxcv","Trainer":"vxzdgvgSv","Status":"gbvsgv"},{"Date":"2012-12-27","Topic":"SDgvsdv","Trainer":"sdvsdv","Status":"sdgvsdv"},{"Date":"2012-12-11","Topic":"sdvsvd","Trainer":"sdvsdv","Status":"vdv"},{"Date":"2012-12-22","Topic":"dvsdv","Trainer":"vssdv","Status":"vsdvV"}] </code></pre> <p>Now what I need is to display this json data in a html table</p> <p>I have displayed all the data in 1 table. But what I need is to get the first 3 data in the first table and all the data in the next table.</p> <p>This is my html code:</p> <pre><code>&lt;!DOCTYPE HTML&gt; &lt;html&gt; &lt;head&gt; &lt;script type="text/javascript" src="jquery182.js"&gt;&lt;/script&gt; &lt;script type="text/javascript" language="javascript"&gt; $(document).ready(function () { $.getJSON('CompletedTraining.php', null, function (data) { var Completed_counter = 1; if (data) { if (Completed_counter &lt;= 3) { var table = '&lt;table border="1"&gt;'; $.each(data, function (i, element) { table += '&lt;tr&gt;'; table += '&lt;td&gt;' + element.Date + '&lt;/td&gt;'; table += '&lt;td&gt;' + element.Topic + '&lt;/td&gt;'; table += '&lt;td&gt;' + element.Trainer + '&lt;/td&gt;'; table += '&lt;td&gt;' + element.Status + '&lt;/td&gt;'; table += '&lt;/tr&gt;'; }); table += '&lt;/table&gt;'; $('#getname').html(table); } var table1 = '&lt;table border="1"&gt;'; $.each(data, function (j, element1) { table1 += '&lt;tr&gt;'; table1 += '&lt;td&gt;' + element1.Date + '&lt;/td&gt;'; table1 += '&lt;td&gt;' + element1.Topic + '&lt;/td&gt;'; table1 += '&lt;td&gt;' + element1.Trainer + '&lt;/td&gt;'; table1 += '&lt;td&gt;' + element1.Status + '&lt;/td&gt;'; table1 += '&lt;/tr&gt;'; }); table1 += '&lt;/table&gt;'; $('#getname1').html(table1); Completed_counter = Completed_counter + 1; } else { alert("error"); } }); }); &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;form name="index"&gt; &lt;table id="getname" &gt;&lt;/table&gt; &lt;table id="getname1" &gt;&lt;/table&gt; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload