Could anyone help me with such issue: I'm trying to make thing, that based on $_Post data I'm showing or not data in the Google tables. (I've removed unnecessary parts of code, that are not actual to this question)
currently, check looks like:
if(!empty($_POST['include_pm'])) {
$pm_script = "data.addColumn('string', 'PM');";
$t0 = ",'\".";
$t1 = '$row['."'".PM."'".']';
$t2 = ".\"'";
$pm_ent = $t0.$t1.$t2;
}
else
{
$pm = "";
$pm_script = "";
$pm_ent = "";
}
And in google visualization table it goes as :
<?php echo $pm_script; ?>
data.addRows([
<?php
foreach ($rows as $row) {
echo "['".$row['TYPE']."'".$pm_ent."],";
}
?>
]);
So basically, when $_POST is empty, nothing is included (as well in script), and it works pretty fine, as needed.
But I'm not able to make it work, when $_POST is not empty: as far as I was experimenting(this one is my last attempt), it printed in the data table exactly string value of the pm_ent value, so it wasn't working in the code as such but became really as a string.
Maybe someone could help me with this, so it would work dynamically - If it's not empty, PM row would be added to the data Rows? As I'm not so good at PHP, I'm having lack of knowledge, how to solve this...
Or maybe there is some smarter way how to do it?
$t1 = '$row['."'".PM."'".']';should probably be$t1 = $row["PM"];Otherwise you'll be outputting the PHP code into javascript, not outputting the value of the PM row.json_encode...?!data.addRows(<?php echo json_encode($rows); ?>);– Never ever should you be manually assembling Javascript code snippets by hand.