I have a PHP file sending data to an external jQuery, it's a dropzone where upload multiple images (each image has different informations inside). I've built a foreach PHP loop which generates arrays (foreach image) and each of those should perform the same functions in that jQuery (delete, update, etc).
How can I send and process the loop from PHP to jQuery?
I'm trying to use the .each method but I guess I'm wronging, because the loop generated shows the same image (with same informations) repeated for the number of arrays!
My PHP
<?php
        $args = array(
            'order'             => 'ASC',
            'orderby'           => 'post_date',
            'post_type'         => 'attachment',
            'author'            => $current_user->ID,
            'meta_key'          => 'is_portfolio',
            'meta_value'        => '1',
            'numberposts'       => -1,
        );
        $attachments = get_posts($args);
        if ($attachments) 
            {
               foreach ($attachments as $attachment) 
                {
                    $url = $attachment->guid;
                    $imggg = $attachment->post_mime_type; 
                    $url = wp_get_attachment_url($attachment->ID); 
                    $thumb = wp_get_attachment_image_src($attachment->ID, 'thumbportfolio');
                    ?>
                    //here is my jQuery array generated for X number of attachments uploaded
                    var mockFile = { 
                        name: "<?php echo $attachment->post_title ?>", 
                        size: 12345, 
                        serverId: '<?php echo $attachment->ID ?>',
                        post_title : "<?php echo $attachment->post_title ?>",
                        post_desc : "<?php echo $attachment->post_content ?>",
                        thumb : "<?php echo $thumb[0] ?>"
                    };
                    <?php           
                }
            } ?>
My jQuery where .each of mockFile ( should initiate a Dropzone Thumb with relative infos and other stuff).
$.each( mockFile, function( index, value ){
        //variables accessing array keys
        var mockThumb = mockFile['thumb'];
        var mockID = mockFile['serverId'];
        var mockTitle = mockFile['post_title'];
        var mockDesc = mockFile['post_desc'];
        //initiate dropzone
        myDropzone.options.addedfile.call(myDropzone, mockFile);
        myDropzone.options.thumbnail.call(myDropzone, mockFile, mockThumb  );
        //Other stuff
        jQuery( "#itemtitle" ).prop( "id","itemtitle-"+mockID);
        jQuery( "#itemtitle-"+mockID ).prop( "value", mockTitle);
        jQuery( "#itemdescription" ).prop( "id","itemdescription-"+mockID );
        jQuery( "#itemdescription-"+mockID ).prop( "value", mockDesc );
        jQuery( "#updateinformations" ).prop( "id","updateinformations-"+mockID );
        change_ids(mockID);
        console.log(mockFile);
    });
Result with this? The same image repeated.
Can you help me?
 
    