我正在尝试使用 Laravel 在下拉选择列表上的 post 方法将三个参数传递给 Controller 。我不知道如何通过第三个。取决于下面MySQL下的另外两个参数:
SELECT id
FROM maintable
WHERE profileId='ValueOfTheFirstSelection'
AND departmentId='ValueOfTheSecondSelection';
我的表单:
<form action="/admin/postmaps" name="form" method="post">
<div class="input-group">
<span class="input-group-addon">Profile ID</span>
<select class="form-control" name="select1" id="select1">
<?php use App\Department; $ids = DB::table('departments')->select('profileId')->get();$a = array();?>
@foreach ($ids as $id )
<?php $a[] = $id->profileId; ?>
@endforeach
<?php $a = array_unique($a); ?>
<option disabled selected value> </option>
@foreach ($a as $element )
<option value="<?php echo $element; ?>">{{ $element }}</option>
@endforeach
</select>
</div>
<div class="input-group">
<span class="input-group-addon">Department ID</span>
<select class="form-control" name="select2" id="select2">
<?php $ids = DB::table('departments')->select( 'id')->get();$b = array();?>
@foreach ($ids as $id )
<?php $b[] = $id->id; ?>
@endforeach
<option disabled selected value> </option>
<?php for ($i = 0; $i < count($b); ++$i) {
echo "<option value='$b[$i]'>".$b[$i]."</option>";
}
?>
</select>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
<button type="submit" class="btn btn-primary" id="updateTerminalInfo">Save</button>
<input type="hidden" value="{{ Session::token() }}" name="_token">
</div>
</form>
最佳答案
在你的 Controller 中:
use DB;
在你的函数中: 提交后
$r = DB::table('Maintable')->select('id')->where('profileId', $request->profileId)
->where('departmentId', $request->departmentId)->get();
关于php - Laravel中基于表单输入的Mysql查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39396943/