Php 如何在选择、复选框和codeigniter中的无线电输入中显示提取的数据?

Php 如何在选择、复选框和codeigniter中的无线电输入中显示提取的数据?,php,codeigniter,Php,Codeigniter,我是codeIgniter的新手,我使用表单插入用户的记录。现在我想获取这些详细信息并在更新表单中显示(我分别创建了插入和更新表单),然后用户可以进行更改。我可以显示输入的type=“text”数据,但我不知道如何显示 在“选择”、“单选”和“复选框”选项中显示资格、性别和工作状态的值。请建议我如何操作 这是我的视图->更新\ u user.php <body> <?php foreach ($data as $row){ ?> <form styl

我是codeIgniter的新手,我使用表单插入用户的记录。现在我想获取这些详细信息并在更新表单中显示(我分别创建了插入和更新表单),然后用户可以进行更改。我可以显示输入的type=“text”数据,但我不知道如何显示 在“选择”、“单选”和“复选框”选项中显示资格、性别和工作状态的值。请建议我如何操作

这是我的视图->更新\ u user.php

<body>
    <?php foreach ($data as $row){ ?>
    <form style=" width:600px;" action="<?php echo base_url('main/updatedata/'.$row->user_id);?>" method="post" class="mx-auto bg-warning">
        <h2 class="text-center p-5">Please fill your details</h2>
        <table align="center" width="80%">
            
            <tr>
                <td class="input-group form-group ">First Name: </td>
                <td>
                    <div class="input-group form-group">
                        <input type="text" name="fname" value="<?php echo $row->firstname; ?>" class="form-control">
                    </div>
                </td>
            </tr>
            <tr>
                <td class="input-group form-group">Last Name: </td>
                <td>
                    <div class="input-group form-group">
                        <input type="text" name="lname" value="<?php echo $row->lastname; ?>" class="form-control">
                    </div>
                </td>
            </tr>
            <tr>
            <tr>
                <td class="input-group form-group">Gender:</td>
                <td>
                    <div class="input-group form-group">
                        <p><input class="mr-2" type="radio" name="gender" value="Male" checked>Male</p>
                        <p class="mx-auto"><input class="mr-2" type="radio" name="gender" value="Female">Female</p>
                        <p><input class="mr-2" type="radio" name="gender" value="Other">Other</p>
                    </div>
                </td>
            </tr>
            <tr>
                <td class="input-group form-group"> Qualification:</td>
                <td>
                    <div class="input-group form-group">
                        <select class="form-control" name="qualification">
                            <option>Uptu 12</option>
                            <option>Bachelors</option>
                            <option>Masters</option>
                            <option>Doctrate</option>
                        </select>
                    </div>
                </td>
            </tr>
            <tr>
                <td class="input-group form-group">Work Status:</td>
                <td>
                    <div class="form-check form-group">
                        <input class="form-check-input" name="work" type="checkbox" value="Full-Time">Full-Time</br>
                        <input class="form-check-input" name="work" type="checkbox" value="Part-Time">Part-Time</br>
                        <input class="form-check-input" name="work" type="checkbox" value="Internship">Internship</br>
                        <input class="form-check-input" name="work" type="checkbox" value="Others">Others</br>
                    </div>
                </td>
            </tr>
            <tr class="input-group form-group align-items-center">
                <td class=""><button type="submit" align="center" value="submit" class="btn btn-success">Update</button></td>
            </tr>
            
        </table>
    </form>
    <?php } ?>
</body>

这是我的模态函数-->

编辑1:此代码是显示所有用户信息的我的视图页面的一部分。当我单击编辑图标时,它将重定向到控制器内的getdataforupdate()函数,以通过用户id获取该用户的所有记录,然后获取的数据应显示在--view('update_user',$result)上.如何在select、radio和checkbox选项中显示数据?这是我的问题

<?php foreach ($data as $row){ ?>
                        <tr>            
                            <td><?php echo $row->user_id; ?></td>
                            <td><?php echo $row->firstname; ?></td>
                            <td><?php echo $row->lastname; ?></td>
                            <td><?php echo $row->email; ?></td>
                            <td><?php echo $row->qualification; ?></td>
                            <td><?php echo $row->salary_expected; ?></td>
                            <td><?php echo $row->gender; ?></td>
                            <td><?php echo $row->location; ?></td>
                            <td><?php echo $row->experience; ?></td>
                            <td><?php echo $row->work_status; ?></td>
                            <td><?php echo $row->user_views; ?></td>
                            <td><a href="<?php echo base_url('main/getdataforupdate/'.$row->user_id);?>"><i class="fas fa-edit" style="font-size:20px;color:yellow;"></i></a></td>
                            <td><a href="<?php echo base_url('main/deletedata/'.$row->user_id);?>"><i class="fas fa-trash-alt" style="font-size:20px;color:red;"></i></a></td>
                        </tr>
                    <?php } ?>

编辑2:一切都按照阿披实·汉饶和韦哈利的更正进行,但我没有勾选复选框。这有什么问题吗?请帮帮我,我找不到错误

<td class="input-group form-group">Work Status:</td>
                <td><?php $work_status = array('work' => $row->work_status);?>
                    <div class="form-check form-group">
                        <input class="form-check-input" name="work[]" type="checkbox" value="Full-Time" <?php if(in_array('Full-Time', $work_status)){ echo 'checked';} ?>>Full-Time</br>
                        <input class="form-check-input" name="work[]" type="checkbox" value="Part-Time" <?php if(in_array('Part-Time', $work_status)){ echo 'checked';} ?>>Part-Time</br>
                        <input class="form-check-input" name="work[]" type="checkbox" value="Internship"<?php if(in_array('Internship', $work_status)){ echo 'checked';} ?>>Internship</br>
                        <input class="form-check-input" name="work[]" type="checkbox" value="Others" <?php if(in_array('Others', $work_status)){ echo 'checked';} ?>>Others</br>
                    </div>
                </td>
工作状态:
>兼职
>其他

您可以尝试以下代码-

<body>
    <?php foreach ($data as $row){ ?>
    <form style=" width:600px;" action="<?php echo base_url('main/updatedata/'.$row->user_id);?>" method="post" class="mx-auto bg-warning">
        <h2 class="text-center p-5">Please fill your details</h2>
        <table align="center" width="80%">
            
            <tr>
                <td class="input-group form-group ">First Name: </td>
                <td>
                    <div class="input-group form-group">
                        <input type="text" name="fname" value="<?php echo $row->firstname; ?>" class="form-control">
                    </div>
                </td>
            </tr>
            <tr>
                <td class="input-group form-group">Last Name: </td>
                <td>
                    <div class="input-group form-group">
                        <input type="text" name="lname" value="<?php echo $row->lastname; ?>" class="form-control">
                    </div>
                </td>
            </tr>
            <tr>
            <tr>
                <td class="input-group form-group">Gender:</td>
                <td>
                    <div class="input-group form-group">
                        <p><input class="mr-2" type="radio" name="gender" value="Male" <?php if($row->gender === "Male"){ echo 'checked'; ?>>Male</p>
                        <p class="mx-auto"><input class="mr-2" type="radio" name="gender" value="Female" <?php if($row->gender === "Female"){ echo 'checked'; ?>>Female</p>
                        <p><input class="mr-2" type="radio" name="gender" value="Other" <?php if($row->gender === "Other"){ echo 'checked'; ?>>Other</p>
                    </div>
                </td>
            </tr>
            <tr>
                <td class="input-group form-group"> Qualification:</td>
                <td>
<!-- Add Value for each option -->
                    <div class="input-group form-group">
                        <select class="form-control" name="qualification">
                            <option value="Uptu 12" <?php if($row->qualification===
                                    "Uptu 12"){ echo "selected"; }?>>Uptu 12</option>
                            <option value="Bachelors" <?php if($row->qualification===
                                    "Bachelors"){ echo "selected"; }?> >Bachelors</option>
                            <option value="Masters" <?php if($row->qualification===
                                    "Masters"){ echo "selected"; }?> >Masters</option>
                            <option value="Doctrate" <?php if($row->qualification===
                                    "Doctrate"){ echo "selected"; }?>>Doctrate</option>
                        </select>
                    </div>
                </td>
            </tr>
            <tr>
<!-- This must be array -->
                <td class="input-group form-group">Work Status:</td>
                <td>
                    <div class="form-check form-group">
                        <input class="form-check-input" name="work[]" type="checkbox" value="Full-Time" <?php if(in_array('Full-Time', $row->work)){ echo 'checked';} ?>>Full-Time</br>
                        <input class="form-check-input" name="work[]" type="checkbox" value="Part-Time" <?php if(in_array('Part-Time', $row->work)){ echo 'checked';} ?>>Part-Time</br>
                        <input class="form-check-input" name="work[]" type="checkbox" value="Internship" <?php if(in_array('Internship', $row->work)){ echo 'checked';} ?>>Internship</br>
                        <input class="form-check-input" name="work[]" type="checkbox" value="Others" <?php if(in_array('Others', $row->work)){ echo 'checked';} ?>>Others</br>
                    </div>
                </td>
            </tr>
            <tr class="input-group form-group align-items-center">
                <td class=""><button type="submit" align="center" value="submit" class="btn btn-success">Update</button></td>
            </tr>
            
        </table>
    </form>
    <?php } ?>
</body>

>男性

>女性

>其他

资格: >Uptu 12 >单身汉 >大师 >医生 工作状态: >全职
>兼职
>实习
>其他
更新
使用表单帮助器查看表单。我没有看到您在哪里执行表单验证,我希望您正在这样做。您应该正在阅读CI用户指南。@TimBrownlaw我只想将获取的数据显示到用户将要进行更新的表单中。我已经为插入和编辑制作了单独的表单。
<td class="input-group form-group">Work Status:</td>
                <td><?php $work_status = array('work' => $row->work_status);?>
                    <div class="form-check form-group">
                        <input class="form-check-input" name="work[]" type="checkbox" value="Full-Time" <?php if(in_array('Full-Time', $work_status)){ echo 'checked';} ?>>Full-Time</br>
                        <input class="form-check-input" name="work[]" type="checkbox" value="Part-Time" <?php if(in_array('Part-Time', $work_status)){ echo 'checked';} ?>>Part-Time</br>
                        <input class="form-check-input" name="work[]" type="checkbox" value="Internship"<?php if(in_array('Internship', $work_status)){ echo 'checked';} ?>>Internship</br>
                        <input class="form-check-input" name="work[]" type="checkbox" value="Others" <?php if(in_array('Others', $work_status)){ echo 'checked';} ?>>Others</br>
                    </div>
                </td>
<body>
    <?php foreach ($data as $row){ ?>
    <form style=" width:600px;" action="<?php echo base_url('main/updatedata/'.$row->user_id);?>" method="post" class="mx-auto bg-warning">
        <h2 class="text-center p-5">Please fill your details</h2>
        <table align="center" width="80%">
            
            <tr>
                <td class="input-group form-group ">First Name: </td>
                <td>
                    <div class="input-group form-group">
                        <input type="text" name="fname" value="<?php echo $row->firstname; ?>" class="form-control">
                    </div>
                </td>
            </tr>
            <tr>
                <td class="input-group form-group">Last Name: </td>
                <td>
                    <div class="input-group form-group">
                        <input type="text" name="lname" value="<?php echo $row->lastname; ?>" class="form-control">
                    </div>
                </td>
            </tr>
            <tr>
            <tr>
                <td class="input-group form-group">Gender:</td>
                <td>
                    <div class="input-group form-group">
                        <p><input class="mr-2" type="radio" name="gender" value="Male" <?php if($row->gender === "Male"){ echo 'checked'; ?>>Male</p>
                        <p class="mx-auto"><input class="mr-2" type="radio" name="gender" value="Female" <?php if($row->gender === "Female"){ echo 'checked'; ?>>Female</p>
                        <p><input class="mr-2" type="radio" name="gender" value="Other" <?php if($row->gender === "Other"){ echo 'checked'; ?>>Other</p>
                    </div>
                </td>
            </tr>
            <tr>
                <td class="input-group form-group"> Qualification:</td>
                <td>
<!-- Add Value for each option -->
                    <div class="input-group form-group">
                        <select class="form-control" name="qualification">
                            <option value="Uptu 12" <?php if($row->qualification===
                                    "Uptu 12"){ echo "selected"; }?>>Uptu 12</option>
                            <option value="Bachelors" <?php if($row->qualification===
                                    "Bachelors"){ echo "selected"; }?> >Bachelors</option>
                            <option value="Masters" <?php if($row->qualification===
                                    "Masters"){ echo "selected"; }?> >Masters</option>
                            <option value="Doctrate" <?php if($row->qualification===
                                    "Doctrate"){ echo "selected"; }?>>Doctrate</option>
                        </select>
                    </div>
                </td>
            </tr>
            <tr>
<!-- This must be array -->
                <td class="input-group form-group">Work Status:</td>
                <td>
                    <div class="form-check form-group">
                        <input class="form-check-input" name="work[]" type="checkbox" value="Full-Time" <?php if(in_array('Full-Time', $row->work)){ echo 'checked';} ?>>Full-Time</br>
                        <input class="form-check-input" name="work[]" type="checkbox" value="Part-Time" <?php if(in_array('Part-Time', $row->work)){ echo 'checked';} ?>>Part-Time</br>
                        <input class="form-check-input" name="work[]" type="checkbox" value="Internship" <?php if(in_array('Internship', $row->work)){ echo 'checked';} ?>>Internship</br>
                        <input class="form-check-input" name="work[]" type="checkbox" value="Others" <?php if(in_array('Others', $row->work)){ echo 'checked';} ?>>Others</br>
                    </div>
                </td>
            </tr>
            <tr class="input-group form-group align-items-center">
                <td class=""><button type="submit" align="center" value="submit" class="btn btn-success">Update</button></td>
            </tr>
            
        </table>
    </form>
    <?php } ?>
</body>