Using mySQL array object as int

I am just starting to learn PHP, javascript and mySQL.

I was able to use PHP to convert mySQL results to json array:

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

      

Now I have a javascript array that I don't know how to use.

If I view "arrayObjects" in the browser console it shows the following:

[Object]
   0: Object
     ID: "1"
     Theme: "2"
     Item1: "0"
     Item2: "1"
     Item3: "2"

      

I would like to use "Theme" as an int in javascript, but I have no idea how I can get this as an int variable.

+3


source to share


2 answers


You can move the value from the array to your own variable, here is a working example:

<?php $results = array( "ID" => 1, "Theme" => 2); ?>
<script>

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

var Theme = arrayObjects['Theme'];

document.write(Theme);

</script>

      



I think you will need to do:

var Theme = arrayObjects[0].Theme;

      

+1


source


I think you should use arrayObjects[0].Theme



+1


source







All Articles