效果图
全部学生信息:
精确查询某位学生完整信息:
学号输入错误:
代码部分
1.Student.php (存储学生信息)
<?php
namespace App\Http\Controllers;
class Student{
public static $students=[
//把复制的学生信息 粘贴在这里面
];
}
?>
2.info.blade.php(全部学生列表)
<body>
<div class="col-md-8">
<h3 style="text-align: center;">学生信息</h3>
<table class="table table-hover table2_4 " style="text-align: center;" align="center"border=0; >
<tr>
<th>编号</th>
<th>学号</th>
<th>姓名</th>
<th>专业</th>
<th>班级</th>
<th>性别</th>
</tr>
@foreach ($students as $item)
<!-- @if ($loop->index%2)
<tr class="table-dark" align="center" >
@else
<tr align="center" >
@endif -->
<tr align="center" >
<td>{{$item['id']}} </td>
<td>{{$item['xh']}} </td>
<td><a href="{{route('ph.show',$item['xh'])}}">{{$item['xingming']}}</a></td>
<td>{{$item['zhuanye']}}</td>
<td>{{$item['banji']}}</td>
<td>{{$item['xingbie']}}</td>
</tr>
@endforeach
</table>
</div>
<style type="text/css">
.bgcolor{
background-color:lightblue ;
}
.table2_4 table {
width:100%;
margin:15px 0
}
.table2_4 th {
background-color:lightblue;
color:white;
}
.table2_4,.table2_4 th,.table2_4 td
{
font-size:20px;
text-align:center;
padding:4px;
border:1px solid #dcf1fc;
border-collapse:collapse
}
/* odd 奇数 */
.table2_4 tr:nth-child(odd){
background-color:#ebf7fd;
}
/* 偶数 */
.table2_4 tr:nth-child(even){
background-color:#fdfdfd;
}
</style>
3.detail.blade.php(查看某位学生的详细信息)
<body>
<div class="col-md-8">
<h1 align="center" >学生详细信息</h1>
<table class="table table-hover table2" >
<caption>信息学院</caption>
<tr>
<th>学号</th>
<th>姓名</th>
<th>性别</th>
<th>年级</th>
<th>专业</th>
<th>班级</th>
<th>教育方式</th>
</tr>
<tr >
@if (empty($stu))
<h2 style="color: red;" align="center">!!!没有该学生信息</h2>
@else
<td >{{$stu['xh']}} </td>
<td>{{$stu['xingming']}}</td>
<td>{{$stu['xingbie']}}</td>
<td>{{$stu['nianji']}}</td>
<td>{{$stu['zhuanye']}}</td>
<td>{{$stu['banji']}}</td>
<td>{{$stu['xuexixingshi']}}</td>
@endif
</tr>
</table>
</div>
<style type="text/css">
.table2 th {
background-color:lightblue;
color:white;
}
.table2 td{
background-color: #ebf7fd;
}
</style>
</body>
4.注意
1.引入boostrap的方式:将boostrap.min.css添加到public目录中
在视图文件的head标签中用link引用
<link rel="stylesheet" type="text/css" href="{{asset('bootstrap.min.css')}}">
2.$loop变量 (引入也需用
{{ }}
来引入)
使用{{ $loop->index }}
可显示当前循环迭代的索引(从0开始)
使用{{$loop->iteration}}
可以得到当前的循环迭代(从1开始)
3.asset()函数:指向public目录,用于引入public目录下的css、js、images等静态文件
4.url()函数:用于生成一个url地址,指向路由。例:<a href="{{ url('/api/user') }}"></a>
5.route()函数:与url作用相同,书写方式不同。例:<a href="{{ route('web.user') }}"></a>