简体   繁体   English

从数据库的列中的表中获取值

[英]get values from table in column from database

I work in a php/wordpress project, and I have table inserted in column in my database like this: 我在php / wordpress项目中工作,并且在数据库的列中插入了表格,如下所示:

meta_value

I like to display values of this table on each input text 我喜欢在每个输入文本上显示此表的值

so for that I tried to do this : 因此,我尝试这样做:

 $mats= get_post_meta($product_id, '_mats', true);
<?php 
     if (!empty($mats)){
        foreach ($mats as $key => $value) {
?>
         <div><input type="text" class="regular-text pro_ele simple variable external grouped" name="mats[]" value="<?php echo $value; ?>" label_class="pro_title"/><a href="javascript:void(0);" class="remove_button" title="Remove field"><img style="height: 20px;width: 20px;" src="https://upload.wikimedia.org/wikipedia/commons/8/85/Ua_3.21_prohibitory-no_entry.svg"/></a></div>
  <?php      
        }

     }
   ?>

the result is this : 结果是这样的: 在此处输入图片说明

but this is what I need: 但这是我需要的: 在此处输入图片说明

Someone please can help me ? 有人可以帮我吗? thanks for all. 谢谢大家

只需将下面的$ value更改为$ value [0]即可。

<div><input type="text" class="regular-text pro_ele simple variable external grouped" name="mats[]" value="<?php echo $value[0]; ?>" label_class="pro_title"/><a href="javascript:void(0);" class="remove_button" title="Remove field"><img style="height: 20px;width: 20px;" src="https://upload.wikimedia.org/wikipedia/commons/8/85/Ua_3.21_prohibitory-no_entry.svg"/></a></div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM