I'm trying to get the selected checkbox value on the edit blade page.
I'm using a query that is used to get student role from users table.
Code in edit.blade.php
<div class="row">
<div class="col-xs-12 col-sm-12 col-md-12">
<div class="form-group">
<strong>Students :</strong>
<div style="margin-top: 5px" >
<?php
$conn = new mysqli('localhost', 'root', '', 'rp') or die ('Cannot connect to db');
$result = $conn->query("select users.id, users.name from users, model_has_roles where model_has_roles.model_id=users.id and model_has_roles.role_id=14;
");
//echo "<select name='name'>";
echo "<html>";
echo "<body>";
while ($row = $result->fetch_assoc()) {
unset($id, $name);
$id = $row['id'];
$name = $row['name'];
echo '<input type=checkbox name="student_id[]" id="student" value="'.$id.'" '.(($ticket->$id == 'student_id' ? 'checked' : '' )).' >'.$name.'';}
echo "</body>";
echo "</html>";
?>
also trying to use other way echo 'echo '<input type=checkbox name="student_id[]" value="'.$id.'" '.( (is_array(old('student_id')) && in_array($id, old('student_id'))) ? ' checked' : '' ).' >'.$name.'';
echo 'echo '<input type=checkbox name="student_id[]" value="'.$id.'" '.( (is_array(old('student_id')) && in_array($id, old('student_id'))) ? ' checked' : '' ).' >'.$name.'';
But still nothing shown.
I would be very thankful if anyone could point-out mistake I'm doing here.
试试这个代码:
<input type="checkbox" value="1" {{$ticket->$id == 'student_id' ? 'checked' : ''}}/>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.