我想从db中搜索和显示特定数据,而我所做的方法不是从数据库中检索数据,如果我打印它只是给出一个空数组。 我的代码如下:
控制器:
public function search() {
$search = Input::get('search');
if($search){
$query = DB::table('volunteer');
$results = $query ->where('bloodt', 'LIKE', $search) ->get();
//print_r($results); exit;
return View::make('search')->with("volunteer",$results);
}
}
查看:
{{Form::open(array('method'=>'POST'))}}
<div class="pull-left col-xs-6 col-xs-offset-0">
{{Form::text('search','',array('placeholder'=>'Search by blood type/zip code/address....','class'=>'form-control','required autofocus'))}}
</div>
<input type="submit" name="search" value="Search" class="btn btn-primary">
<br><br>
{{Form::close()}}
<?php if (isset($results)) { ?>
@foreach($volunteer as $results)
<table class="table table-bordered" style="width: 100%; background-color: lightsteelblue">
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>IC/Passport no.</th>
<th>Blood Type</th>
<th>Address</th>
<th>Zip Code</th>
<th>e-mail</th>
<th>Phone no.</th>
<th>Status</th>
</tr>
<tr>
<td>{{ $results->fname }}</td>
<td>{{ $results->lname }}</td>
<td>{{ $results->ic }}</td>
<td>{{ $results->bloodt }}</td>
<td>{{ $results->address }}</td>
<td>{{ $results->zipcode }}</td>
<td>{{ $results->email }}</td>
<td>{{ $results->phone }}</td>
<td>
<div class="btn-group" role="group">
<button class="btn btn-default dropdown-toggle" data-toggle="dropdown">
{{ $results->status }}
<span class="caret"></span>
</button>
<ul class="dropdown-menu">
<li><a href="#">Eligible</a></li>
<li><a href="#">Not Eligible</a></li>
</ul>
</div>
</td>
</tr>
</table>
@endforeach
<?php;
} ?>
路线:
Route::post('search', 'HomeController@search');