如何根据数据动态填充表

时间:2014-02-08 20:35:33

标签: javascript php jquery html mysql

这是我的HTML代码

<table data-role="table" id="movie-table" data-filter="true" data-input="#filterTable-input" class="ui-responsive">
    <thead>
        <tr>
            <th data-priority="1">Rank</th>
            <th data-priority="persist">Player Name</th>
            <th data-priority="2">Record</th>
            <th data-priority="3"><abbr title="Rotten Tomato Rating">Points</abbr></th>
            <th data-priority="4">Highlight</th>
        </tr>
        </thead>
        <tbody >
        <div id="table"></table>


        </tbody>
    </table>
**This is my Javascript/Jquery**
$( document ).ready(function() 
{
$.get('./php/rank.php', function(data)
 {
 $('#table').html(data);



}).error(function() {

 $('#table').append('An error has occured');


} ).success (function(){

 $('#table').append(''); 

})




});
**This is my php**
echo "<tr>";    
         echo "<th>". $row1['points']."<td/>";
    echo "<td>". $row1['points']."<td/>";
    echo "<td>". $row1['points']."<td/>";
       echo "<td>". $row1['points']."<td/>";
        echo "<td>". $row1['points']."<td/>";
echo "</tr>";

我想要完成的是根据注册用户填充表格。一世 试图回应整个表 - 没有成功(我正在使用JQuery Mobile)所以我想也许我可以只是回应th和td标签会有所不同。任何建议将不胜感激,也许我只是错误的方式。谢谢

3 个答案:

答案 0 :(得分:0)

您没有正确关闭代码。此外,不需要div insde tbody(我不知道它是否被允许)。尝试使用此更正的代码:

<table data-role="table" id="movie-table" data-filter="true" data-input="#filterTable-input" class="ui-responsive">
    <thead>
        <tr>
            <th data-priority="1">Rank</th>
            <th data-priority="persist">Player Name</th>
            <th data-priority="2">Record</th>
            <th data-priority="3"><abbr title="Rotten Tomato Rating">Points</abbr></th>
            <th data-priority="4">Highlight</th>
        </tr>
    </thead>
    <tbody>

    </tbody>
</table>
**This is my Javascript/Jquery**
$( document ).ready(function() 
{
$.get('./php/rank.php', function(data)
 {
 $('#movie-table tbody').html(data);



}).error(function() {

 $('#movie-table tbody').append('An error has occured');


} ).success (function(){

 $('#movie-table tbody').append(''); 

})




});
**This is my php**
echo "<tr>";    
         echo "<th>". $row1['points']."</th>";
    echo "<td>". $row1['points']."</td>";
    echo "<td>". $row1['points']."</td>";
       echo "<td>". $row1['points']."</td>";
        echo "<td>". $row1['points']."</td>";
echo "</tr>";

编辑,当然您不想在所有五列中显示字段“分数”。

答案 1 :(得分:0)

我解决了。在php中你必须回应完整的表格。

echo "<table data-role='table' id='movie-table' data-filter='true' data-input='#filterTable-input' class='ui-responsive'>";
  echo  "<thead>";

echo "<tr>";
           echo "<th data-priority='1'>Rank</th>";
            echo "<th data-priority='persist'>Player Name</th>";
           echo "<th data-priority='2'>Record</th>";
           echo "<th data-priority='3'><abbr title='Rotten Tomato Rating'>Points</abbr></th>";
            echo "<th data-priority='4'>Highlight</th>";
    echo    "</tr>";
      echo  "</thead>";

while($row1 = mysql_fetch_array($result1)){ 



       echo "<tbody>";
            echo "<tr>";
                echo "<th>1</th>";
                echo "<td>Kentwan</td>";
                echo "<td>10-0</td>";
                echo "<td>1000</td>";
               echo "<td>test</td>";
            echo "</tr>";


        echo "</tbody>";

}


echo "</table>";

答案 2 :(得分:0)

尝试这样的事情:

<table data-role="table" id="movie-table" data-filter="true" data-input="#filterTable-input" class="ui-responsive">
    <thead>
        <tr>
            <th data-priority="1">Rank</th>
            <th data-priority="persist">Player Name</th>
            <th data-priority="2">Record</th>
            <th data-priority="3"><abbr title="Rotten Tomato Rating">Points</abbr></th>
            <th data-priority="4">Highlight</th>
        </tr>
    </thead>
    <tbody id='tab_body'>

    </tbody>
</table>

**你的Javascript / Jquery **

$( document ).ready(function() 
{
$.get('./php/rank.php', function(data)
 {
 $('#tab_body').html(data);

})
}