【问题标题】:Showing select option list (Dropdown) in dynamic html+php table在动态 html+php 表中显示选择选项列表(下拉)
【发布时间】:2017-05-11 18:26:53
【问题描述】:

正如您在这张图片中看到的,我扫描产品的条形码,插入 mysql 表并通过自动刷新将该 mysql 表检索到此页面中。每次我扫描不同的产品时,都会根据 mysql 表添加新行。

使用这些代码我检索 mysql 表并在 html 表中回显:

<table id="dataTable" class="table table-condensed table-bordered" style="margin-top:0px">
    <tbody>
    <?php
    $sat_fatura_no = $_GET['sat_fatura_no'];
    $liste_cek = @mysql_query("SELECT * FROM alisfat_listesi WHERE fatura_no = '".$sat_fatura_no."'");
    while ($a= mysql_fetch_array($liste_cek)){
        $stok_kodu2 = $a['stok_kodu'];

        $isim_cek = mysql_query("SELECT * FROM stoklar WHERE sto_RECno = '".$stok_kodu2."'");
        while ($isim_al=mysql_fetch_array($isim_cek)){
            $urun_isim = $isim_al['sto_isim'];
        }
        $kdv    = $a['kdv'];

        $kdv_cek = mysql_query("SELECT * FROM kdvler WHERE kdv_id = '".$kdv."'");
        while ($kdv_al = mysql_fetch_array($kdv_cek)){
            $kdv_isim = $kdv_al['kdv_isim'];    
        }

        $kdv_cek1 = mysql_query("SELECT * FROM kdvler");
        while ($kdv_al1 = mysql_fetch_array($kdv_cek1)){
            $kdv_id1    = $kdv_al1['kdv_id'];
            $kdv_isim1  = $kdv_al1['kdv_isim'];
        }

        echo '<tr>
            <td width="5%"><a href="satir_sil.php?stok_kodu='.$stok_kodu2.'&sat_fatura_no='.$sat_fatura_no.'"><button class="btn btn-mini btn-danger  input1">Sil</button></a></td>

            <td width="25%"><input class="input1" type="hidden" name="sth_stok_kod[]" value="'.$stok_kodu2.'" readonly>'.$urun_isim.'</td>

            <td width="10%"><input style="text-align:center" class="input1" type="text" name="sth_adet[]" value="" required></td>

            <td width="10%">
                <select style="margin: 0 !important; padding: 0 !important; width:100%" name="sth_birim[]" required>
                    <option value="" selected>Seçiniz</option>
                    <?php $brim2_bul = mysql_query("SELECT * FROM birimler");
                    while($brim2_cek = mysql_fetch_array($brim2_bul)){
                        echo "<option ";
                        echo "value="".$brim2_cek["birim_id"]."">". $brim2_cek["birim_isim"]."</option>";
                    } ?>
                 </select>
            </td>

            <td width="10%"><input class="input1" type="text" id="sth_birim_fiyat" name="sth_birim_fiyat[]" required></td>

            <td width="10%">
                <select style="margin: 0 !important; padding: 0 !important; width:100%" name="sth_kdv" required>
                    <option value="<?php echo $stok_vergisi; ?>" selected><?php echo $stok_vergisi; ?></option>
                    <?php $kdv2_bul = mysql_query("SELECT * FROM kdvler");
                    while($kdv2_cek = mysql_fetch_array($kdv2_bul)){
                        echo '<option ';
                        echo 'value="'.$kdv2_cek['kdv_isim'].'">' .$kdv2_cek['kdv_isim'].'</option>';
                    } ?>
                 </select>
            </td>

            <td width="10%"><input class="input1" type="text" id="sth_iskonto1" name="sth_iskonto1[]" required></td>

            <td width="10%"><input class="input1" type="text" id="sth_iskonto2" name="sth_iskonto2[]" required></td>    

            <td width="10%"><input class="input1" type="text" id="sth_tutar" name="sth_tutar[]" required></td>
        </tr>';
    } ?>
    </tbody>
</table>

我无法修复的唯一部分是那些 SELECT OPTION 部分。通常我可以使用这些选择选项 php 代码检索 mysql 表的每一行,但是当我将它们放在 php echo 中时,通常我无法从数据库中检索任何值。

所以任何人都知道如何让这些选择下拉菜单在 php echo 中保持活跃?

【问题讨论】:

    标签: php html mysql drop-down-menu dynamic-tables


    【解决方案1】:

    您不应在 echo 字符串中使用 PHP 标记。将它们分开。先结束echo字符串语句,再使用PHP逻辑语句。我已经更新了你的代码:

    <table id="dataTable" class="table table-condensed table-bordered" style="margin-top:0px">
        <tbody>
        <?php
        $sat_fatura_no = $_GET['sat_fatura_no'];
        $liste_cek = @mysql_query("SELECT * FROM alisfat_listesi WHERE fatura_no = '".$sat_fatura_no."'");
        while ($a= mysql_fetch_array($liste_cek)){
            $stok_kodu2 = $a['stok_kodu'];
    
            $isim_cek = mysql_query("SELECT * FROM stoklar WHERE sto_RECno = '".$stok_kodu2."'");
            while ($isim_al=mysql_fetch_array($isim_cek)){
                $urun_isim = $isim_al['sto_isim'];
            }
            $kdv    = $a['kdv'];
    
            $kdv_cek = mysql_query("SELECT * FROM kdvler WHERE kdv_id = '".$kdv."'");
            while ($kdv_al = mysql_fetch_array($kdv_cek)){
                $kdv_isim = $kdv_al['kdv_isim'];    
            }
    
            $kdv_cek1 = mysql_query("SELECT * FROM kdvler");
            while ($kdv_al1 = mysql_fetch_array($kdv_cek1)){
                $kdv_id1    = $kdv_al1['kdv_id'];
                $kdv_isim1  = $kdv_al1['kdv_isim'];
            }
    
            echo '<tr>
                <td width="5%">
                    <a href="satir_sil.php?stok_kodu='.$stok_kodu2.'&sat_fatura_no='.$sat_fatura_no.'">
                        <button class="btn btn-mini btn-danger  input1">Sil</button>
                    </a>
                </td>
    
                <td width="25%">
                    <input class="input1" type="hidden" name="sth_stok_kod[]" value="'.$stok_kodu2.'" readonly>'.$urun_isim.'
                </td>
    
                <td width="10%">
                    <input style="text-align:center" class="input1" type="text" name="sth_adet[]" value="" required>
                </td>
    
                <td width="10%">
                    <select style="margin: 0 !important; padding: 0 !important; width:100%" name="sth_birim[]" required>
                        <option value="" selected>Seçiniz</option>';
    
                        $brim2_bul = mysql_query("SELECT * FROM birimler");
                        while($brim2_cek = mysql_fetch_array($brim2_bul)){
                            echo '<option value="'.$brim2_cek["birim_id"].'">'. $brim2_cek["birim_isim"].'</option>';
                        }
    
                     echo '</select>
                </td>
    
                <td width="10%">
                    <input class="input1" type="text" id="sth_birim_fiyat" name="sth_birim_fiyat[]" required>
                </td>
    
                <td width="10%">
                    <select style="margin: 0 !important; padding: 0 !important; width:100%" name="sth_kdv" required>
                        <option value="'.$stok_vergisi.'" selected>'.$stok_vergisi.'</option>';
    
                        $kdv2_bul = mysql_query("SELECT * FROM kdvler");
                        while($kdv2_cek = mysql_fetch_array($kdv2_bul)){
                            echo '<option value="'.$kdv2_cek['kdv_isim'].'">' .$kdv2_cek['kdv_isim'].'</option>';
                        }
    
                    echo '</select>
                </td>
    
                <td width="10%">
                    <input class="input1" type="text" id="sth_iskonto1" name="sth_iskonto1[]" required>
                </td>
    
                <td width="10%">
                    <input class="input1" type="text" id="sth_iskonto2" name="sth_iskonto2[]" required>
                </td>    
    
                <td width="10%">
                    <input class="input1" type="text" id="sth_tutar" name="sth_tutar[]" required>
                </td>
            </tr>';
        } ?>
        </tbody>
    </table>
    

    试试这个,希望它能解决你的问题。

    【讨论】:

    • 非常感谢..您的解决方案也修复了它。
    【解决方案2】:

    **重新整理如下代码**

    <table id="dataTable" class="table table-condensed table-bordered" style="margin-top:0px">
    <tbody>
    
     <?php
     $sat_fatura_no = $_GET['sat_fatura_no'];
     $liste_cek = @mysql_query("SELECT * FROM alisfat_listesi WHERE fatura_no = '".$sat_fatura_no."'");
               while ($a= mysql_fetch_array($liste_cek)){
                    $stok_kodu2 = $a['stok_kodu'];
    
                    $isim_cek = mysql_query("SELECT * FROM stoklar WHERE sto_RECno = '".$stok_kodu2."'");
                                while ($isim_al=mysql_fetch_array($isim_cek)){
                                $urun_isim = $isim_al['sto_isim'];
                                }
                    $kdv    = $a['kdv'];
    
                    $kdv_cek = mysql_query("SELECT * FROM kdvler WHERE kdv_id = '".$kdv."'");
                                while ($kdv_al = mysql_fetch_array($kdv_cek)){
                                $kdv_isim = $kdv_al['kdv_isim'];    
                                }
                    $kdv_cek1 = mysql_query("SELECT * FROM kdvler");
                                while ($kdv_al1 = mysql_fetch_array($kdv_cek1)){
                                $kdv_id1    = $kdv_al1['kdv_id'];
                                $kdv_isim1  = $kdv_al1['kdv_isim']; }
    
                    ?>
                    <tr>
    
     <td width="5%"><a href="satir_sil.php?stok_kodu=<?php echo $stok_kodu2;?>&sat_fatura_no=<?php echo $sat_fatura_no;?>">
     <button class="btn btn-mini btn-danger  input1">Sil</button></a></td>
    
    <td width="25%"><input class="input1" type="hidden" name="sth_stok_kod[]" value="<?php echo $stok_kodu2;?>" readonly><?php echo $urun_isim;?></td>
    
    <td width="10%"><input style="text-align:center" class="input1" type="text" name="sth_adet[]" value="" required></td>
    
    <td width="10%"><select style="margin: 0 !important; padding: 0 !important; width:100%" name="sth_birim[]" required>
    <option value="" selected>Seçiniz</option>
    <?php $brim2_bul = mysql_query("SELECT * FROM birimler");
    while($brim2_cek = mysql_fetch_array($brim2_bul)){ ?>
    <option value="<?php echo $brim2_cek["birim_id"];?>"><?php echo $brim2_cek["birim_isim"];?></option>
    <?php } ?>
     </select></td>
    
    <td width="10%">
    <input class="input1" type="text" id="sth_birim_fiyat" name="sth_birim_fiyat[]" required>
    </td>
    
    <td width="10%">
    <select style="margin: 0 !important; padding: 0 !important; width:100%" name="sth_kdv" required>
    <option value="<?php echo $stok_vergisi; ?>" selected><?php echo $stok_vergisi; ?></option>
    <?php $kdv2_bul = mysql_query("SELECT * FROM kdvler");
    while($kdv2_cek = mysql_fetch_array($kdv2_bul)){ ?>
    <option value="<?php echo $kdv2_cek['kdv_isim'];?>"><?php echo $kdv2_cek['kdv_isim'];?></option>
    <?php } ?>
     </select>
    </td>
    
    <td width="10%">
    <input class="input1" type="text" id="sth_iskonto1" name="sth_iskonto1[]" required>
    </td>
    
    <td width="10%">
    <input class="input1" type="text" id="sth_iskonto2" name="sth_iskonto2[]" required>
    </td>   
    
    <td width="10%">
    <input class="input1" type="text" id="sth_tutar" name="sth_tutar[]" required>
    </td>
    </tr>
    <?php } ?>
    </tbody>
    </table>
    

    【讨论】:

      猜你喜欢
      • 2012-08-12
      • 1970-01-01
      • 1970-01-01
      • 2015-06-16
      • 2017-03-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-10-28
      相关资源
      最近更新 更多