【问题标题】:how to filter data in select option and display it as a report (php: laravel framework)如何过滤选择选项中的数据并将其显示为报告(php:laravel框架)
【发布时间】:2015-12-07 03:49:28
【问题描述】:

如何过滤选择选项中的数据并将其作为报告显示在另一个表格中。我不知道如何使用 JavaScript。

下面是我的report.blade.php

<table width="100%">
    <div id="DrpDwn" align="center">
        <h1> report</h1> <br/>
        Programme:<select id="program">
            @foreach($profiles as $profile)
                <option>{{$profile->program}}</option>
            @endforeach
        </select><br>
        Faculty:<select id="faculty">
            @foreach($profiles as $profile)
                <option> {{$profile->faculty}}</option>
            @endforeach
        </select>
    </div>
    <br />
    <table id="tableID" border="2" width="100%">
        <tr>
            <td class="student_id" width="15%">Student id </td>
            <td class="name" width="30%">name</td>
            <td class="program" width="30%"> Program</td>
            <td class="faculty" width="25%">Faculty </td>
        </tr>
        @foreach($profiles as $profile)
        <tr>
            <td class="student_id" width="15%">{{$profile->student_id }}</td>
            <td class="name" width="30%">{{$profile->student_name }}</td>
            <td class="program" width="30%"> {{$profile->program }}</td>
            <td class="faculty" width="25%">{{$profile->faculty }} </td>
        </tr>
        @endforeach
    </table>
    </table>

我想要这样.. 当我单击程序:文凭多媒体时,它将仅显示与之相关的数据。 (对不起我的英语不好)

【问题讨论】:

  • 您是在寻求 JS 帮助还是非 js 解决方案?
  • 哪一个容易理解?

标签: javascript php jquery laravel-5.1


【解决方案1】:

首先:您应该在控制器中创建一个函数,该函数从数据库中返回所有表行:

function getTableRows($faculty)
{
$rows = Student:::where('faculty', '=', $faculty)
foreach ($rows as $row)
{

echo "<tr><td>".$row->student_id."</td><td>".$row->name."</td><td>".$row->faculty."</td></tr>";
}
}

然后在laravel的route.php中为这个函数做路由,并在select的onchange事件中用ajax调用这个函数:

 $(document).ready(function() { 

$("#faculty").change(function() { 
     //your route
     $.get("student/getTableRows/"+$(this).val(), function(html) { 
         // append the "ajax'd" data to the table body 
         $("#tableID tbody").append(html); 

    }); 

}); 
});

你也应该ajax表行,或者动态ajax表,jquery ajax表。

【讨论】:

    【解决方案2】:
    <select id = 'program'>      </select>
    <div id = 'tableID'></div>
    

    现在在您的 javascript 页面中

    $("#program").bind("change", function() {
        $.ajax({
            type: "GET", 
            url: "path/to/server/script.php",
            data: "id="+$("#program").val(),
            success: function(html) {
                $("#tableID").html(html);
            }
        });
        });
    

    【讨论】:

    • 我没有过滤数据 :(
    猜你喜欢
    • 1970-01-01
    • 2022-01-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-14
    • 1970-01-01
    • 2016-10-13
    • 1970-01-01
    相关资源
    最近更新 更多