2

I need to pass an array as a function argument from php to js.i am getting the values from database.

while ($rows = pg_fetch_array($qry))
        {
            ?>
            <option  value="<?php echo $rows['relation_name_local']?>">
            <?php echo $rows['relation_name_local']?>
            </option>
            <?php
            $app_relation_array[] =  $rows['relation_name_local'];
        }?>

i want to pass $app_relation_array[] values through addNewRow() this function Can anyone please help me with this. Thanks a lot.

1

2 Answers 2

2

Use json_encode() function and echo it in javascript

    while ($rows = pg_fetch_array($qry))
    {
        ?>
        <option  value="<?php echo $rows['relation_name_local']?>">
        <?php echo $rows['relation_name_local']?>
        </option>
        <?php
        $app_relation_array[] =  $rows['relation_name_local'];
        $new_data = json_encode($app_relation_array[]);
    }?>

And in your html inside script tag

     <script>
        var data = JSON.parse("<?php echo $new_data; ?>");
        alert(data);
     </script>
0

Use json_encode function in php

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.