Jump to content
ThalieMTL

Easy ? Display Array values

Recommended Posts

Hi, 

It's my first time here. I'm not a coder but I sometimes need to find solutions by myself so here I am...

I think this one will be easy for all of you.

I generate a PDF displaying data from fields on a DB

They all display very well except the multiple choices.

Here is an exerpt of my code; I tried the implode code to display my values separated by commas but in the document it stil displays "Array" (screenshot enclosed) instead of something like: "Sante mentale, Reussite scolaire, Environnement sain "

And I obviously don't know what's wrong...

<tr><td><?php echo $fields['prenomact']['value']; ?> <?php echo $fields['nomact']['value']; ?></td><td><?php echo $fields['titreact']['value']; ?></td></tr>
<tr><td><?php echo $fields['courrielact']['value']; ?></td><td><?php echo $fields['telact']['value']; ?></td></tr>
<tr><td>Enjeux visés: <?php $fields['enjeux']=implode(",", $array); echo $fields['enjeux']['value'];?></td><td>territoire: <?php echo $fields['territoire']['value']; ?></td></tr>
<tr><td>Participation des enfants: <?php echo $fields['niveauparticipation']['value']; ?></td><td>Nombre d'enfants participants : <?php echo $fields['nbenfants']['value']; ?></td></tr>

Thanks in advance for your help,

Valérie

 

Capture d’écran 2018-12-02 à 12.25.15.png

Share this post


Link to post
Share on other sites

The real problem is you are improperly storing your data. Do not store your data as comma separated values.  Fix the database first. You need to learn about "Database Normalization".

Share this post


Link to post
Share on other sites

Thanks for your quick response benanamen !

Hum... OK but the data is collected and stored by a WP plugin named Ninja Forms.

Their basic pdf was only  saying:

<html><head>
    <link type="text/css" href="<?php echo $css_path; ?>" rel="stylesheet" />
</head><body>
    <h1><?php echo $title; ?></h1>
    <?php echo $table; ?>
</body></html>

And the fields were very well displayed, separated by commas... I needed to customize the PDF so I recreated it field by field.

Share this post


Link to post
Share on other sites

You get "Array" output when you attempt to echo an array variable.

$myArr = [1,2,3];
echo $myArr;          //--> Array

I have no idea what your data structure is, but it looks like $fields['niveauparticipation']['value']  is an array.

[EDIT]Try this to check

echo '<pre>', print_r($fields, 1), '</pre>';

 

Edited by Barand

Share this post


Link to post
Share on other sites

Hi everyone and thank you for your help.

FYI, I just solved it with this code:

<?php echo implode(",",$fields['enjeux']['value']);?>

Many many thanks again!!

Valérie

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.