下拉列表,当数据库中没有数据无法手动输入时

时间:2018-07-19 09:46:57

标签: php codeigniter drop-down-menu html.dropdownlistfor

enter image description here我正在使用下拉列表创建程序。
因此这里是“ Pilih Unit Mesin”形式,其中数据库中具有数字“ Torsi”的机器单元将自动以“ Torsi”形式出现数字

问题是如果机器单元中的数据库中没有数字,我希望以“ Torsi”的形式可以手动输入数字

请帮助,谢谢

_renderNoPlaying = (item) => {
   return ( 
     <View style={styles.horizontalContainer}> 
     <Image 
       	source={{uri : item.img!=null?item.img:nullImg.nil}} 
       	resizeMethod={'scale'} 
     	style={{
     		width:150,
     		height:120, 
     		borderTopLeftRadius:20,
     		borderTopRightRadius:20}}
     /> 
     <Text style={styles.titleItem}>{item.key}</Text> 
)}

enter image description here 截屏1:
enter image description here 截屏2:
enter image description here 截屏3:
enter image description here enter image description here

1 个答案:

答案 0 :(得分:0)

您可以组合多个数组函数来检查多维数组中的特定键是否不为空:

<label>Torsi</label>
<?php
if (empty(array_filter(array_column($poross, 'torsi_poros')))) {
?>
<input type="number" name="torsi" id="torsi" class="form-control" >
<?php } else { ?>
<select class="form-control" name="torsi" id="torsi" required="">

<?php foreach ($poross as $key => $val) :?>
    <?php if ($val['torsi_poros'] != null): ?>
        <option <?php echo $poros_selected == $val['id_unit'] ? 'selected="selected"' : '' ?> 
        class="<?php echo $val['id_unit'] ?>" value="<?php echo $val['torsi_poros'] ?>"><?php echo $val['torsi_poros'] ?></option>
        <span class="input-group-addon">Kg.mm</span>

        <?php elseif ($val['torsi_poros'] != ""): ?>
        <option <?php echo $poros_selected == $val['id_unit'] ? 'selected="selected"' : '' ?> 
        class="<?php echo $val['id_unit'] ?>" value="<?php echo $val['torsi_poros'] ?>"><?php echo $val['torsi_poros'] ?></option>
        <span class="input-group-addon">Kg.mm</span>
        </div>     
    <?php endif; ?>
<?php endforeach?>
</select>
<?php } ?>
<br>

使用array_column返回数组中单个列的值,然后使用array_filter丢弃空数组。