Passing array from PHP to JS |
[eluser]agubski[/eluser]
Hi Everyone, I'm having a technical problem to pass an array (which is database query) to JS on the page. Any help will be appreciated. Code: <?php foreach($query->result() as $row): ?>
[eluser]Colin Williams[/eluser]
Look at json_encode() for one option. Code: print json_encode($query->result());
[eluser]madeks[/eluser]
I guess your problem is the generated JS is a multiple line of string? The easiest way may be to use a library to handle it like Colin said. Or you may want to search the google for a multiple line of JS string.
[eluser]agubski[/eluser]
I have found a relatively easy solution. here it is: Code: <?php now I have another problem of generating 3 php arrays from database query output. each array must contain values for a specific database field (column) I'm using follwing construct; Code: <?php foreach($query->result_array() as $row): ?> |
Welcome Guest, Not a member yet? Register Sign In |