How to pass a PHP fix to a javascript function

0

My javascript code is to generate a random number and show it, but I want it to only show it if it is not already included in the array it is the name of the varible ' arr '

<script type="text/javascript">
    function aleatorio(a,b, arr) {
     var numal = Math.round(Math.random()*(b-a)+parseInt(a));
    if (arr.includes( numa1 ) )
    {
        aleatorio(a,b, arr);
    }
    else
    {
        document.getElementById("sugest").innerHTML=": "+ numal;
    }   
      }
</script>

Now I have the fix in php of a query .... I get it like this:

$query = sprintf("SELECT * FROM db_tabla WHERE id_art = %s",  
GetSQLValueString($colname_Articulo, "int"));
$datos = mysqli_query($connect, $query) or die(mysqli_error($connect));
$row_datos = mysqli_fetch_assoc($datos);
$totalRows_datos = mysqli_num_rows($datos);

$i=1;

do{
$all [$i]= $row_datos['numero'];
$i++;
}while(($row_datos = mysqli_fetch_assoc($datos))&&($i<=$totalRows_datos))

 ?>

and I call the function like this:

<button type="button" onClick="aleatorio(1,<?php echo $max ?>,
<?php echo $all ?>);" >Sugerencia   </button> 

In this case he tells me that:

  

notice: array to string conversion

Try to do a json_encode , but I do not know how to check inside the function whether the num is in the json or not ...

    
asked by Maite 19.03.2018 в 17:15
source

0 answers