dousongqiang2585 2016-05-26 10:06
浏览 87

显示MySQL数据库中多个复选框的值

I have a form that uses several checkbox fields to save profile data.

The values are being submitted to the database like 1, 2 courtesy of imploding the $_POST variable but I can't seem to figure out how explode them on a profile page and display the values.

My submit code (part of the insert query);

$profile_piercings = implode(", ", $_POST['profile_piercings']);

My profile code to echo out the values;

<?php if(!empty($profile['profile_piercings'])){ ?>
<dt>Piercings</dt>
<dd><?php //echo $profile['profile_piercings'] ?>
<?php 
$piercing_values = $profile['PiercingsText'];
$piercings = explode(", ", $piercing_values);
echo $piercing_values; ?></dd>
<?php } ?>

When printing the exploded array, it looks as though my query has only passed the first value. I need to do it this way to translate a numeric value into the corresponding text value (eg 1 = ears).

An extract of my SQL code;

frmhaircolour.id,
                frmhaircolour.textvalue AS HairColourText,
                frmpiercings.id,
                frmpiercings.textvalue AS PiercingsText,
FROM profiles
            LEFT JOIN frmeyecolour ON profiles.profile_eyecolour = frmeyecolour.id
            LEFT JOIN frmhaircolour ON profiles.profile_haircolour = frmhaircolour.id
            LEFT JOIN frmpiercings ON profiles.profile_piercings = frmpiercings.id
  • 写回答

2条回答 默认 最新

  • doq13207 2016-05-26 10:10
    关注

    Iterate through on your array:

    $piercings = explode(", ", $piercing_values);
    foreach ($piercings as $piercing) {
       echo $piercing."<br>";
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?