I declare php arrays, i fill them with strings taken from query. I have to pass this arrays to a handler of a element in the page. Handler can't read this arrays.
PHP:
$names = $paths = $infos= [];
$i = 0;
while($row = $result->fetch_row())
{
$names[$i]= $row[0];
$paths[$i]= $row[1];
$infos[$i]= $row[2];
$i++;
}
...
for($i = 1; $i < ($length/8)+1 ; $i++)//arrotonda per eccesso
{
$jsNames = json_encode($names);
$jsInfo = json_encode($infos);
$jsPaths = json_encode($paths);
//echo $jsNames."<br>";
//echo $jsInfo."<br>";
//echo $jsPaths."<br>";
?>
<a href="#" onClick="changePhoto(<?php echo $i.','.$jsNames.','.$jsInfo.','.$jsPaths ?>)" class="w3-bar-item w3-white w3-button"> <?php echo $i ?></a>
JS:
function changePhoto(num,names,paths,infos){
//nothing
}
Browser error: Uncaught SyntaxError: Unexpected token }
Opening browser debugger:
(function(event){changePhoto(2,[ })
echoes?"in it. So try to changeonClick="..."toonClick='....'(function(event){changePhoto(2,[ })echo $i.",'".$names[$i]."','".$infos[$i]."','".$paths[$i]