I was looking for a simple way to create a javaScript array when streaming out my php code.
my php sql query generates a quick rowset result in an associative array like this.
Then when streaming out the page, inserting the following in the page header
But of course this simple example simply generates a javaScript array with no content.
Is it only possible to copy this data using two loops. Where in outer loop you cycle through the php array. And in the inner loop you cycle through each column of that specific row?
What I was looking for was a better way.
When streaming out my page to the client computer, I was looking for a quick way to insert this data into a javaScript array on the resulting page web page. I was hoping not to have to loop through the php array and extract each column in each row.
my php sql query generates a quick rowset result in an associative array like this.
Code:
if ( $result = $db->query($sql) )
{
if ($result->num_rows > 0)
{
$f = mysqli_fetch_all( $result, $resulttype = MYSQLI_ASSOC );
}
}
Code:
<script type="text/javascript"> var exportArray = <?php echo $f;?>; </script>
Is it only possible to copy this data using two loops. Where in outer loop you cycle through the php array. And in the inner loop you cycle through each column of that specific row?
What I was looking for was a better way.
When streaming out my page to the client computer, I was looking for a quick way to insert this data into a javaScript array on the resulting page web page. I was hoping not to have to loop through the php array and extract each column in each row.
Comment