[英]how to filter data in select option and display it as a report (php: laravel framework)
How can I filter the data in select option and display it in another table as a report. 如何在选择选项中过滤数据并将其作为报告显示在另一个表中。 i do not know how to use JavaScript.
我不知道如何使用JavaScript。
Below is my report.blade.php 以下是我的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>
i want like this.. when i click programme: diploma multimedia, it will show data that related to it only. 我想要这样..当我单击程序:文凭多媒体时,它将仅显示与之相关的数据。 (sorry for my broken english)
(对不起,我的英语不好)
Firstly: you should make a function in your controller which return all tables rows with data from database: 首先:您应该在控制器中创建一个函数,该函数返回所有表行以及数据库中的数据:
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>";
}
}
Then you will make route for this function in route.PHP in laravel,and call this function with ajax in onchange event of select: 然后您将在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);
});
});
});
Also you should ajax table rows, or dynamic ajax table, jquery ajax table. 另外,您应该使用ajax表行或动态ajax表,jquery ajax表。
<select id = 'program'> </select>
<div id = 'tableID'></div>
Now in your javascript page 现在在您的JavaScript页面中
$("#program").bind("change", function() {
$.ajax({
type: "GET",
url: "path/to/server/script.php",
data: "id="+$("#program").val(),
success: function(html) {
$("#tableID").html(html);
}
});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.