填充下拉框,同时填充表 [英] Populate Dropdown Boxes while also Populating Table

查看:223
本文介绍了填充下拉框,同时填充表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用foreach循环填充的表格。我的一个专栏是SKU Group,它是一列下拉框。但是,每当foreach循环运行,只有该行的一个相应的值显示在下拉框内。



我怎样才能得到它,以便我可以运行的foreach循环,它正确填充表,而下拉列表也填充每个SKU组的名称,而不是每个行对应的单个值?
$ b

正常情况下,我只需运行这个 foreach($ var-> fetchAll()as $ var1)下拉列表来填充它们,但我不认为它可以在已经运行的另一个循环内正常运行。所以这就是为什么我有这个问题。
$ b $ p

HTML Table:

 < table id =skuTablecellspacing =5class =ui-widget ui-widget-content> 
< thead>
< tr class =ui-widget-header>
< th style =display:none>产品ID< / th>
< th class =skuRow>主要类别< / th>
< th class =skuRow>次要类别< / th>
< th class =skuRow>报告码< / th>
< th class =skuRow> SKU< / th>
< th class =skuRow> SKU状态< / th>
< / tr>
< / thead>
< tbody>

<?php foreach($ dbh-> query($ query)as $ row){?>

< tr>
< td style =display:noneclass =prod_idid =product_id-<?php echo intval($ row ['Product_ID'])?>><?php echo $行[ 'PRODUCT_ID']>?< / TD>
< td class =major_catid =major_cat-<?php echo intval($ row ['Major Category'])?>><?php echo $ row ['Major Category ]>?< / TD>
< td class =minor_catid =minor_cat-<?php echo intval($ row ['Minor Category'])?>><?php echo $ row ['Minor Category ]>?< / TD>
< td class =rep_codeid =rep_code-<?php echo intval($ row ['Product Report Code'])?> align =center><?php echo $ row ['Product Report Code']?>< / td>
< td class =skuid =sku-<?php echo intval($ row ['SKU'])?> align =center><?php echo $ row ['SKU']?>< / td>
< td class =sku_descid =sku_desc-<?php echo intval($ row ['SKU Description'])?>><?php echo $ row ['SKU说明]>?< / TD>
< td class =sku_statusid =sku_status-<?php echo intval($ row ['SKU Status'])?> align =center><?php echo $ row ['SKU Status']?>< / td>
< td class =create_dateid =create_date-<?php echo intval($ row ['Date'])?> align =center><?php echo $ row ['Date']?>< / td>
< td class =sku_groupid =sku_group-<?php echo intval($ row ['SKU Group'])?>对齐= 中心 >

< select id =sku_group_dropdown>
< option
value =
data-name =<?php echo $ row ['SKU Group'];?>
>
<?php echo $ row ['SKU Group'];?>
< / option>
< / select>

< / td>
< td>< input type =buttonclass =editname =editvalue =Edit>< / td>
< / tr>

<?php}?>

< / tbody>
< / table>


解决方案

首先需要使用循环填充下拉列表



 <?php 
$ i = 0;
$ content ='';
$ names = array('Test1','Test2');
foreach($ names as $ row){
if($ i == 0){
$ names = array('Test1','Test2'); //替换它echo $行['SKU组'];

foreach($ names as $ key)
{
$ content。='< option value ='。$ key。'>'。$ key。 '< /选项>';
}
}
$ i ++;
?>

< tr>
< td> sadasdsa< / td>
< td class =sku_groupid =sku_group-<?php echo intval($ row ['SKU Group'])?>对齐= 中心 >

< select id =sku_group_dropdown>
<?php echo $ content?>
< / select>

< / td>
< td>< input type =buttonclass =editname =editvalue =Edit> < / TD>
< / tr>

<?php}?>

在这个代码中替换你的数组数据,或者如果你想在你的循环之外填充下拉数据,您的群组资料可以使用此代码


I have a table that is populated using a foreach loop. One of my columns is SKU Group, which is a column of dropdown boxes. However, whenever the foreach loop runs, only the one corresponding value for that row is displayed inside the dropdown box.

How can I get it so that I can run the foreach loop and it correctly populates the table, while the dropdowns are also populated with every SKU Group name and not just the single value that corresponds with each row?

Normally, I would just run this foreach($var->fetchAll() as $var1) for the dropdowns to populate them, but I dont think that it can be ran properly inside another loop that is already running. So that is why I am having this issue.

HTML Table:

<table id="skuTable" cellspacing="5" class="ui-widget ui-widget-content">
    <thead>
        <tr class="ui-widget-header">
            <th style="display: none">Product ID</th>
            <th class="skuRow">Major Category</th>
            <th class="skuRow">Minor Category</th>
            <th class="skuRow">Report Code</th>
            <th class="skuRow">SKU</th>
            <th class="skuRow">SKU Description</th>
            <th class="skuRow">SKU Status</th>
            <th class="skuRow">Create Date</th>
            <th class="skuRow">SKU Group</th>
            <th class="skuRow">Edit</th>
        </tr>
    </thead>
    <tbody>

        <?php foreach ($dbh->query($query) as $row) {?>

        <tr>
            <td style="display: none" class="prod_id" id="product_id-<?php echo intval ($row['Product_ID'])?>"><?php echo $row['Product_ID']?></td>
            <td class="major_cat" id="major_cat-<?php echo intval ($row['Major Category'])?>"><?php echo $row['Major Category']?></td>
            <td class="minor_cat" id="minor_cat-<?php echo intval ($row['Minor Category'])?>"><?php echo $row['Minor Category']?></td>
            <td class="rep_code" id="rep_code-<?php echo intval ($row['Product Report Code'])?>" align="center"><?php echo $row['Product Report Code']?></td>
            <td class="sku" id="sku-<?php echo intval ($row['SKU'])?>" align="center"><?php echo $row['SKU']?></td>
            <td class="sku_desc" id="sku_desc-<?php echo intval ($row['SKU Description'])?>"><?php echo $row['SKU Description']?></td>
            <td class="sku_status" id="sku_status-<?php echo intval ($row['SKU Status'])?>" align="center"><?php echo $row['SKU Status']?></td>
            <td class="create_date" id="create_date-<?php echo intval ($row['Date'])?>" align="center"><?php echo $row['Date']?></td>
            <td class="sku_group" id="sku_group-<?php echo intval ($row['SKU Group'])?>" align="center">

                <select id="sku_group_dropdown">
                    <option
                        value=""
                        data-name="<?php echo $row ['SKU Group'];?>"
                    >
                        <?php echo $row ['SKU Group'];?>
                    </option>
                </select>

            </td>
            <td><input type="button" class="edit" name="edit" value="Edit"></td>
        </tr>

    <?php } ?>

    </tbody>
</table>

解决方案

first need to populate your dropdown list using loop

<?php 
 $i = 0;
 $content = '';
  $names =  array('Test1','Test2');
  foreach ($names as $row) {
  if($i== 0){  
  $names =  array('Test1','Test2');// replace it  echo $row ['SKU Group'];

  foreach($names as $key)
  {
   $content .= '<option value="'.$key.'">'.$key.'</option>';    
  }
   } 
  $i++;
  ?>

  <tr>
   <td>sadasdsa</td>
    <td class="sku_group" id="sku_group-<?php echo intval ($row['SKU Group'])?>" align="center">

    <select id="sku_group_dropdown">
    <?php echo $content?>
    </select>

     </td>
        <td><input type="button" class="edit" name="edit" value="Edit">                  </td>
       </tr>

          <?php } ?>

in this code replace your array data or if you want to populate dropdown data outside your loop then first get your group data for you can use this code

这篇关于填充下拉框,同时填充表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆