0

UPDATED:

I want to update variable($_accordionHeader) via javascript/jquery after loop in php. I can pass variable from PHP to javascript but it is not working in loop/ in this case.

$cmd_select_lic = "SELECT * FROM lic WHERE id_inst = $id_inst";
$q_select_licencje = mysqli_query($_conn, $cmd_select_lic);

//(...code...)//


  $_accordionHeader = '';

  while($rows = mysqli_fetch_assoc($q_select_licencje))
  {
  ob_start();   

    <button class="accordion"><?php echo $_accordionHeader ?></button> // <-- i want update this variable after each loop
       <div class="panel">

       //(...code...)//

      foreach($rows as $k=>$v)
      {

         if($k == 'no_lic')
           $_accordionHeader .= '<b>No lic: </b>' . $v;
         if($k == 'name_lic')
           $_accordionHeader .= ' / <b>Name lic: </b>' . $v;
         if($k == 'data_start')
           $_accordionHeader .= ' / <b>Start date: </b>' .$v;

          // (...code...) //
       }

   ?>

    <script type="text/javascript">
      var text = '<?php echo $_accordionHeader ?>';
      document.getElementsByClassName("accordion").textContent = text;
    </script>
   <?php

  ob_get_flush();
  }

I tried a lot of things but nothing worked. The $_accortionHeader is empty. Is there any other way to do it?

matisetorm
  • 857
  • 8
  • 21
Kafus
  • 101
  • 10

0 Answers0