Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

Here is my code: I am getting data from mysql query and getting array of values. But i am not able to populate in javasript. could you please any one help me out...

PHP Code:

   $parishFamilyInfo = $parishFamilyInfoBO->sendBirthdayGreeting($personalInfoSearchDO,  $parishFamilyInfoSearchDO);
    foreach ($parishFamilyInfo as $parishFamily){
       if(!empty($parishFamily->email)){
               print_r($parishFamily);
     }
   }    

JavaScript:

$(document).ready(function(){
var t = $('#people').bootstrapTransfer(
    {'target_id': 'multi-select-input',
         'height': '15em',
         'hilite_selection': true});
        t.populate([   /*here i need to populate php array value*/
            {   
                value:"<?php print_r($parishFamily->email);?>", 
                content:"<?php print_r($parishFamily->name);?>"
            },
        ]);


        //t.set_values(["2", "4"]);
        //console.log(t.get_values());

    });

share|improve this question
add comment

1 Answer

print_r is only for debugging. It's not for anything else. Let me quote the documentation:

print_r — Prints human-readable information about a variable

As stated above, it is a debugging function that's used to print the contents of a variable in a more readable manner. It just returns a string — JavaScript does not and will not understand this format.

Use JSON (JavaScript Object Notation) instead. It is is a light-weight data interchange format that is very popular nowadays. You can use the built-in function json_encode to create the JSON representation of your PHP array and then transfer it to JavaScript. JSON being language independent and based on the JavaScript scripting language, your JavaScript code will now be able to parse the array:

t.populate([
    {   
        value: <?php echo json_encode($parishFamily->email); ?>, 
        content: <?php echo json_encode($parishFamily->name); ?>
    },
]);
share|improve this answer
    
thanks for your time and info. –  muralidego Mar 28 at 6:30
    
@user1450403: Did this answer solve your issue? If so, please consider marking it as accepted –  Amal Murali Mar 28 at 6:42
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.