在 foreach 中使用反序列化标记收音机

我想知道如何正确地选中复选框。


当前在循环内循环......


首先,foreach它列出了所有要标记的选项,如下图所示:


在此处输入图片说明


第二个foreach是标记来自数据库的选项。它使用此代码进行检查<?php  if($checkIni[$key] == "tem"){echo "checked ";}; ?>。变化的是TEM, NAO, AVA 的值。


<?php

    $checklistIni = "a:16:{i:0;s:3:"nao";i:1;s:3:"ava";i:2;s:3:"tem";i:3;s:3:"tem";i:4;s:3:"tem";i:5;s:3:"tem";i:6;s:3:"tem";i:7;s:3:"tem";i:8;s:3:"tem";i:9;s:3:"tem";i:10;s:3:"tem";i:11;s:3:"tem";i:12;s:3:"tem";i:13;s:3:"tem";i:14;s:3:"tem";i:15;s:3:"tem";}";


    $checkIni = unserialize($checklistIni );


    foreach($rsChecklist as $checklist) {

        foreach($checkIni as $key => $val){


?>



  <tr>

    <td class="texto-branco">

      <?php echo $checklist['nome'] ?>

    </td>

    <td><label><input value="tem" name="checklistFim<?php echo $checklist['ID_Checklist'] ?>" class="checklistFim" type="radio" <?php  if($checkIni[$key] == "tem"){echo "checked ";}; ?> /><span></span></label></td>

    <td><label><input value="nao" name="checklistFim<?php echo $checklist['ID_Checklist'] ?>" class="checklistFim" type="radio" <?php  if($checkIni[$key] == "nao"){echo "checked ";}; ?> /><span></span></label></td>

    <td><label><input value="ava" name="checklistFim<?php echo $checklist['ID_Checklist'] ?>" class="checklistFim" type="radio" <?php  if($checkIni[$key] == "ava"){echo "checked ";}; ?> /><span></span></label></td>

  </tr>



  <?php

        };

    };

?>


拉莫斯之舞
浏览 156回答 1
1回答

ITMISS

你的代码有点乱,顺便说一下,希望我能帮到你:$checklistIni = 'a:16:{i:0;s:3:"nao";i:1;s:3:"ava";i:2;s:3:"tem";i:3;s:3:"tem";i:4;s:3:"tem";i:5;s:3:"tem";i:6;s:3:"tem";i:7;s:3:"tem";i:8;s:3:"tem";i:9;s:3:"tem";i:10;s:3:"tem";i:11;s:3:"tem";i:12;s:3:"tem";i:13;s:3:"tem";i:14;s:3:"tem";i:15;s:3:"tem";}';$checkIni = unserialize($checklistIni);$rsChecklist = array(array(&nbsp; &nbsp; 'nome' => 'A',));foreach ($rsChecklist as $k => $checklist) {foreach ($checkIni as $key => $val) {&nbsp; &nbsp; ?>&nbsp; &nbsp; <table>&nbsp; &nbsp; &nbsp; &nbsp; <tr>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <td class="texto-branco">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <?php echo $checklist['nome'] ?>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </td>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <td><label><input value="tem" name="checklistFim<?php echo $key ?>" class="checklistFim"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; type="radio" <?php if ($val == "tem") {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; echo "checked='checked' ";&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }; ?> /><span></span></label></td>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <td><label><input value="nao" name="checklistFim<?php echo $key ?>" class="checklistFim"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; type="radio" <?php if ($val == "nao") {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; echo "checked='checked' ";&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }; ?> /><span></span></label></td>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <td><label><input value="ava" name="checklistFim<?php echo $key ?>" class="checklistFim"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; type="radio" <?php if ($val == "ava") {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; echo "checked='checked' ";&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }; ?> /><span></span></label></td>&nbsp; &nbsp; &nbsp; &nbsp; </tr>&nbsp; &nbsp; </table>&nbsp; &nbsp; <?php}}本质上,您必须更改这些行<input value="tem" name="checklistFim<?php echo $checklist['ID_Checklist'] ?>" class="checklistFim" type="radio" <?php&nbsp; if($checkIni[$key] == "tem"){echo "checked ";}; ?> /> 。name车道中三个无线电中的每一个的属性必须相同,并且与其他车道不同。
打开App,查看更多内容
随时随地看视频慕课网APP