jeudi 26 mai 2016

Displaying values of multiple checkboxes from MySQL database

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




Aucun commentaire:

Enregistrer un commentaire