I have JavaScript in my php file. It’s executed on timer. It displays counter by console.log()
But my php code that I need to work doesn’t seem to be executed. I inserted there echo $Max_id;
, but I don’t see in browser it printed. Neither do I see console.log($Max_id)
in debug. Why is this?
Heres my script:
view_topic.php:
<script>
const CheckReload = (() => {
let counter = - 40;
return () => {
<?php
$tbl_name = fanswer;
$sql7="SELECT MAX(a_id) AS Maxa_id FROM $tbl_name WHERE question_id='$id'";
$result7=mysql_query($sql7);
$rows7=mysql_fetch_array($result7);
// if there no answer yet set it = 0
if ($rows7) {
$Max_id = $rows['Maxa_id'];
}
else {
$Max_id = 0;
}
console.log($Max_id); // cannot see it printed
echo $Max_id; // nor this
if ($rows2['a_id'] < $Max_id) {
echo "location.reload();";
console.log("location.reload();");
}
?>
counter++;
return counter;
};
})();
{
const refreshId = setInterval(
() => {
const properID = CheckReload();
console.log(properID);
if (properID > 0) {
clearInterval(refreshId);
}
},
1000
);
}
</script>