ThalieMTL Posted December 2, 2018 Share Posted December 2, 2018 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 Quote Link to comment Share on other sites More sharing options...
benanamen Posted December 2, 2018 Share Posted December 2, 2018 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". Quote Link to comment Share on other sites More sharing options...
ThalieMTL Posted December 2, 2018 Author Share Posted December 2, 2018 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. Quote Link to comment Share on other sites More sharing options...
Barand Posted December 2, 2018 Share Posted December 2, 2018 (edited) 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 December 2, 2018 by Barand Quote Link to comment Share on other sites More sharing options...
ThalieMTL Posted December 2, 2018 Author Share Posted December 2, 2018 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.