douxing9641 2015-01-21 16:37
浏览 23
已采纳

从数据库中获取序列化的Dropdown Multiselect

I have a multiselect dropdown that stores the data in an array and inserts by serialize () to the database. I wonder how I can bring this data back to your checkboxs marked like the image. Can anyone help me please?

Dropdown Multiselect

Insert:

$sql = "INSERT INTO programacao 
  (programacao_id, painel_id, palestrante_id, tipo_programacao_id, dia,hora_inicio,hora_fim, palestrantes, imagem,cor_fundo,ativo) 
  VALUES
  (:programacao_id, :painel_id, :palestrante_id, :tipo_programacao_id, :dia,:hora_inicio,:hora_fim,:palestrantes, :imagem,:cor_fundo,:ativo)";
  $dadosBind = array(
    'programacao_id' => $novo_id,
    'painel_id' => $painel_id,
    'palestrante_id' => $palestrante_id,
    'tipo_programacao_id' => $tipo_programacao_id,
    'dia' => $uteis->dataBr2Bd($dia),
    'hora_inicio' => $hora_inicio,
    'hora_fim' => $hora_fim,
    'palestrantes' => serialize($palestrantes),
    'imagem' => ( isset($nome_final_foto) )?$nome_final_foto  :'',
    'cor_fundo' => $cor_fundo,
    'ativo' => $ativo
  );
  $insertProgramacao = $db->ubQuery($sql, $dadosBind);

Listing:

$sql = "SELECT palestrantes.palestrante_id, palestrantes.nome FROM palestrantes INNER JOIN programacao
          ON palestrantes.palestrante_id = programacao.palestrante_id WHERE programacao.programacao_id = $programacao_id AND palestrantes.palestrante_id = programacao.palestrante_id";
  $dados_palestrantes = $db->query($sql); 
  $dados_palestrantes = $dados_palestrantes[0];

Foreach to insert:

<label>
            Palestrantes
            <select multiple="multiple" name="palestrantes[]" placeholder="&nbsp;" class="SlectBox">
              <?php
              foreach ($lista_palestrantes as $palestrantes) {
                echo '<option value="'.$palestrantes['nome'].'">'.$palestrantes['nome'].'</option>';
              }
              ?>
            </select>
          </label>

Data in DB:

a:4:{i:0;s:20:"Alexandre";i:1;s:11:"Antonio";i:2;s:28:"Arlindo";i:3;s:25:"Carlos";}
  • 写回答

1条回答 默认 最新

  • dongtuo5611 2015-01-21 16:43
    关注

    Fetch your selected items from the database/$_POST and loop through them. In the html:

    if($palestrantes['id'] == $fetched_item['id']){
        echo '<option value="'.$palestrantes['nome'].'" checked="true">'.$palestrantes['nome'].'</option>';
        //----------------------------------------------^^^^^^^^^^^^^^
    }
    else{
        echo '<option value="'.$palestrantes['nome'].'">'.$palestrantes['nome'].'</option>';
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#vscode#的问题:ESP32开发板对接MQTT实现小灯泡的开关
  • ¥15 TMC2209串口模式下读取不到寄存器的值串口助手蓝色字体是发过去的消息,绿色字体是收到的消息,第二行发送读取寄存器的指令但是没有读取到寄存器的值串口助手如下图:接线如下图,如何解决?
  • ¥15 高通安卓11提取完整线刷包软件,或者优博讯dt50顺丰刷机包
  • ¥20 C,有个译码器,换了信道就跑不出原来数据
  • ¥15 MIMIC数据库安装问题
  • ¥60 基于JTag协议开发Fpga下载器上位机,哪位大🐂有偿指导?
  • ¥20 全书网Java爬取数据
  • ¥15 怎么获取红包封面的原始链接,并且获取红包封面序列号
  • ¥100 微信小程序跑脚本授权的问题
  • ¥100 房产抖音小程序苹果搜不到安卓可以付费悬赏