0

I have a web page that displays several albums and the following html code for an album icon that should allow the user to change the access settings to the specific album ($row holds the response values from a db query that returns info on albums)

<a data-title="'.$row['title'].'" data-description="'.$row['description'].'" data-id="'.$row['photoCollectionId'].'" class="open-update_dialog2" data-toggle="modal" href="#update_dialog2">
 <i class="ace-icon fa fa-eye"></i>
</a>

and if the user clicks on it, a modal shows up

<div class="modal fade" id="update_dialog2" role="dialog">
 <div class="modal-dialog">
  <div class="modal-content">
   <ul id="check-list-box" class="list-group checked-list-box">
     <?php
      foreach (getFriends($email) as $row) {
      $flag = checkAccessRights($row['email'],1)['value'];
      echo '<li class="list-group-item" data-checked='.$flag.'>'.$row['firstName'].' '.$row['lastName'].'</li>';
      }
     ?>
  </ul>  
 </div>
</div>
</div>

.js

$(document).on("click", ".open-update_dialog2", function () {
     albumName = $(this).data('title');
     $(".modal-body #albumName").val(albumName);
     albumDescription = $(this).data('description');
     $(".modal-body #albumDescription").val(albumDescription);
     albumId = $(this).data('id');

});

My problem is that each modal would need to fetch different data depending on the album the user clicked on and thus I want to replace the value of 1 in checkAccessRights($row['email'],1) with the value of the variable albumName. Is there a way to get the value from jquery to php? Any tip would be greatly appreciated!

KeykoYume
  • 2,497
  • 6
  • 24
  • 48
  • Possible duplicate of [Assign jquery value to php variable](http://stackoverflow.com/questions/36026673/assign-jquery-value-to-php-variable) – KeykoYume Feb 19 '17 at 14:19

2 Answers2

0

You can use ajax,

This (Ajax) help you to create dynamic album.

aya
  • 1,597
  • 4
  • 29
  • 59
0

JQuery it is a client side, PHP it is a server. So you should send request to the server with albumId parameter.

$(document).on("click", ".open-update_dialog2", function () {
    albumName = $(this).data('title');
    $(".modal-body #albumName").val(albumName);
    albumDescription = $(this).data('description');
    $(".modal-body #albumDescription").val(albumDescription);
    albumId = $(this).data('id');

    $.get("yourPhpFile.php", {albumId:albumId}).done(function(resp) {
       // 
    });

});

and on your server you need get this parameter and put in your loop

<div class="modal fade" id="update_dialog2" role="dialog">
  <div class="modal-dialog">
    <div class="modal-content">
      <ul id="check-list-box" class="list-group checked-list-box">
       <?php
         $albumId = $_GET['albumId'] ? $_GET['albumId'] : 1;
         foreach (getFriends($email) as $row) { 
           $flag = checkAccessRights($row['email'], $albumId)['value'];
           echo '<li class="list-group-item" data-checked='.$flag.'>'.$row['firstName'].' '.$row['lastName'].'</li>';
          }
        ?>
      </ul>  
   </div>
 </div>

Pasha
  • 621
  • 8
  • 21