Because I do not print the data from the database assigned to variable Jquery

0

** Why it shows Notice error: Array to string conversion in C: **

Inspertor Inspertor

   
  <script>
    $('document').ready(function() {
      <?php 
         $consulta="SELECT idCategoria FROM buscar_categoria";
         $resultado=$conexion->query($consulta)or die("Error de busqueda o conexion");

         while ($paisBuscado=$resultado->fetch_assoc() ) {
       ?>  
          var paisBuscado = "<?php echo $paisBuscado; ?>";
          document.write(paisBuscado);

   <?php  
     }
    ?>
</script>
    
asked by Gamez 10.03.2017 в 20:13
source

3 answers

1

I assume that what returns to you is an arrangement is better if you work it in this way

var paisBuscado = <?php echo json_encode($paisBuscado); ?>

in the case that you have a result you should be able to access the data with paisSearch.idCategoria for example.

but if the is a single value the subject should be.

var paisBuscado = "<?php echo $paisBuscado['idCategoria'] ?>";

I hope I can help you and the error is because you are trying to convert an array to a string.

    
answered by 10.03.2017 в 20:22
1

If you make echo to an array there will always be an error of Array to string conversion.

You should do, instead:

var paisBuscado = "<?php echo $paisBuscado['idCategoria']; ?>";
    
answered by 10.03.2017 в 21:00
0

Notice apparently or die is stuck to the left parenthesis, I do not know if you were wrong to paste the code, or if it is typed. able and that's why it does not work for you, since apparently the syntax is fine.

    
answered by 10.03.2017 в 20:18