Hi,
thanks for your question, and sorry for the trouble.
Is your $i
variable really increasing in your code?
Also, no matter how many values you would have in that “what_type_of_mental_health_professional_are_you_” field, it would be overwritten each time. Your loop simply is wrong for what you want to do, I think.
Regards,
Tobias
Thread Starter
Anonymous User 13716511
(@anonymized-13716511)
Yes the $i is increasing as it should in the code. The loop seems to be correct, I’ve used it in other places just I can’t seem to store more then one value in the variable $table[‘data’][$i][1];
if I echo $value all the values are shown so why if I set $table[‘data’][$i][1] = $value; is only one value shown?
Thread Starter
Anonymous User 13716511
(@anonymized-13716511)
If $table[‘data’][$i][1] = $field;
where $field is an array I get the errors:
`Warning: substr() expects parameter 1 to be string, array given in xxx/wp-content/plugins/tablepress/classes/class-render.php on line 562
Warning: nl2br() expects parameter 1 to be string, array given in xxx/wp-content/plugins/tablepress/classes/class-render.php on line 766
if I try and loop through the array with an if($field as $fields){ $table[‘data’][$i][1] = $fields; } I can only get the last value in the array.
$table[‘data’][$i][1] = $field[0] . $field[1] . $field[2] gives me the correct data but I need to loop through it, how can I do this?
Thank you so much for your help
Hi,
well, $table[‘data’][$i][1]
is a string in itself, so setting
$table[‘data’][$i][1] = $value;
simply sets the string to a new one every time.
What you want is to concatenate the existing value with the new piece. For that, you’d need e.g. code like
$table['data'][$i][1] = $table['data'][$i][1] . ' ' . $value;
or the shorter version
$table['data'][$i][1] .= ' ' . $value;
Regards,
Tobias
Thread Starter
Anonymous User 13716511
(@anonymized-13716511)
Thank you so much for explaining that. I didn’t realise that was the case. I spent hours on this.
It is working now.
Thank you for your great plugin and your amazing prompt support! Really appreciated.
Hi,
no problem, you are very welcome! 🙂 Good to hear that this helped!
This is the same for any other variable in PHP, nothing special. It might just be confusing that you are dealing with a multidimensional array here.
Best wishes,
Tobias
P.S.: In case you haven’t, please rate TablePress here in the plugin directory. Thanks!