Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/255.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/76.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Jquery数据表父子数据_Php_Jquery_Datatables - Fatal编程技术网

Php Jquery数据表父子数据

Php Jquery数据表父子数据,php,jquery,datatables,Php,Jquery,Datatables,我正在使用它来显示子行。我使用php返回一个数组或数据。我有它的运作相当好,但有几个问题 这是我目前拥有的图像。 如图所示,有两个父行具有相同的问题,而子行具有不同的答案 1。我需要一种方法来限制每个不同问题的父行。 2。我还需要一种在同一子表中循环显示多个子行的方法。 <table id="car" class="display" cellspacing="0" width="100%"> <thead> <tr>

我正在使用它来显示子行。我使用php返回一个数组或数据。我有它的运作相当好,但有几个问题

这是我目前拥有的图像。

如图所示,有两个父行具有相同的问题,而子行具有不同的答案

1。我需要一种方法来限制每个不同问题的父行。

2。我还需要一种在同一子表中循环显示多个子行的方法。

<table id="car" class="display" cellspacing="0" width="100%">
      <thead>
         <tr>
           <th class="details-control" style="max-width: 80px;">Expand</th>
           <th>Question</th>
         </tr>
       </thead>
       <tbody>
       </tbody>
        <tfoot>
           <tr>
             <th></th>
             <th>Question</th>
           </tr>
         </tfoot>
       </table>
3。另一个选项是如何将数据分配给父行,将另一组数据分配给子行。

我知道我应该在查询中这样做,但问题列是单对多结果,在两个单独的表中。处理查询的唯一方法是为问题返回一个结果,然后进行另一个ajax调用来填充子行。我想这会更容易些

代码:

表格:

<table id="car" class="display" cellspacing="0" width="100%">
      <thead>
         <tr>
           <th class="details-control" style="max-width: 80px;">Expand</th>
           <th>Question</th>
         </tr>
       </thead>
       <tbody>
       </tbody>
        <tfoot>
           <tr>
             <th></th>
             <th>Question</th>
           </tr>
         </tfoot>
       </table>

扩大
问题:
问题:
脚本:

 function format(d) {
        //d is the original data object for the row
        var tbl = '<table cellpadding="5" cellspacing="0" border="0" style="margin-left:110px; width:100%; font-size:12px;">' +
              '<tr>' +
              '<th style="width:60%; color:3383bb;">Answer Choices</th>' +
              '<th style="width:15%; color:3383bb;"># of Answers</th>' +
              '<th style="width:15%; color:3383bb;">Percentage</th>' +
              '</tr>' + '<tr>' +
              '<td>' + d.Answer + '</td>' +
              '<td>' + d.NumberOfAnswers + '</td>' +
              '<td>' + d.Percent + '</td>' +
              '</tr>' + '</table>';
        return tbl;
    }


    var table2 = $('#car').DataTable({
        "ajax": "/rmsicorp/clientsite/reset/survey/surveyajax.php",
        "scrollY": "400px",
        "paging": false,
        "bAutoWidth": true,
        "columns": [
            {
                "className": 'details-control',
                "orderable": false,
                "data": null,
                "defaultContent": ''
            },
            { "data": "Question" },
        ],
    }).columns.adjust().draw();
函数格式(d){
//d是行的原始数据对象
变量tbl=''+
'' +
“答案选择”+
"答案"+
“百分比”+
'' + '' +
“+d.回答+”+
“+d.NumberOfAnswers+”+
“+d.百分比+”+
'' + '';
返回tbl;
}
变量表2=$('#car')。数据表({
“ajax”:“/rmsicorp/clientsite/reset/survey/surveyajax.php”,
“滚动”:“400px”,
“分页”:false,
“bAutoWidth”:没错,
“栏目”:[
{
“className”:“详细信息控制”,
“可订购”:错误,
“数据”:空,
“defaultContent”:”
},
{“数据”:“问题”},
],
}).columns.adjust().draw();
查询结果:

 function format(d) {
        //d is the original data object for the row
        var tbl = '<table cellpadding="5" cellspacing="0" border="0" style="margin-left:110px; width:100%; font-size:12px;">' +
              '<tr>' +
              '<th style="width:60%; color:3383bb;">Answer Choices</th>' +
              '<th style="width:15%; color:3383bb;"># of Answers</th>' +
              '<th style="width:15%; color:3383bb;">Percentage</th>' +
              '</tr>' + '<tr>' +
              '<td>' + d.Answer + '</td>' +
              '<td>' + d.NumberOfAnswers + '</td>' +
              '<td>' + d.Percent + '</td>' +
              '</tr>' + '</table>';
        return tbl;
    }


    var table2 = $('#car').DataTable({
        "ajax": "/rmsicorp/clientsite/reset/survey/surveyajax.php",
        "scrollY": "400px",
        "paging": false,
        "bAutoWidth": true,
        "columns": [
            {
                "className": 'details-control',
                "orderable": false,
                "data": null,
                "defaultContent": ''
            },
            { "data": "Question" },
        ],
    }).columns.adjust().draw();


问题栏只是针对每个答案重复。其余的列是不同的。

这是一个常见问题,您可以在查询端或语言端解决它。在这种情况下,我更喜欢语言方面。您可以尝试做什么:

  • 按问题文本进行查询的顺序
  • 检查最后一个问题和实际问题是否有相同的文本
  • 如果是,请在实际问题中添加答案
  • 否则,创建一个新的问题条目

  • 您必须编辑您的格式函数才能执行此操作,我建议您将其分为两部分,一部分带有问题标题,另一部分带有答案数据,然后您可以控制:渲染或不渲染标题。

    如何检索记录?第1行:|问题1 |答案1 |第2行:|问题1 |答案2 |第3行:|问题2 |答案1 |诸如此类?更新的问题,请参阅帖子底部。