0
$i = 0;
while($row = $statement->fetch()) {
    $current_id = 'id-' . $i;
    $i++;
    echo "
        <tr>
            <td>
                <p>
                    <button class='btn btn-primary' 
                         type='button' 
                         data-toggle='collapse' 
                         data-target='#<?=$current_id?>' 
                         aria-expanded='false' 
                         aria-controls='Collapse'>
                        Button with data-target
                    </button>
                </p>
                <div class='collapse' id='<?=$current_id?>'>
                    <div class='card card-block'>
                        Here is the content for block which will be shown when the button. This uses button with data-target attribute for collapsing.
                    </div>
                </div>
            </td>
    ";
}

Where is my error? It doesn't collapse but I need the unique ids for my rows.

Barry
  • 3,303
  • 7
  • 23
  • 42
AndyDE
  • 1
  • 3
  • 1
    Not sure if it solves your problem. Unless it was an error while copying over to your question, you're missing a closing bracket `}` for your `while` loop. – Mark Oct 19 '18 at 07:25
  • This `}` is there its only a snipped of this td where the collapse is :) But i have this `}` in my code :) this error is only here when i change data-target to normal like #ttt and id to ttt then it toogles but with this try i dont :) – AndyDE Oct 19 '18 at 07:27
  • Possible duplicate of [bootstrap initially collapsed element](https://stackoverflow.com/questions/16149923/bootstrap-initially-collapsed-element) - I think you need `
    – Ken Y-N Oct 19 '18 at 07:30
  • BTW, I added a closing `}` just for completeness. – Ken Y-N Oct 19 '18 at 07:34
  • `class='accordian-body collapse' id...` do not work for me. – AndyDE Oct 19 '18 at 07:35
  • Too late to edit it, but the spelling is actually `accordion-body`. Does that work instead? – Ken Y-N Oct 19 '18 at 07:37
  • No it dont work. I tried only `accordian-body` this show the text bellow the button but this is not the correct one. i need to toogle it :) and `accordian-body collapse` do not work . – AndyDE Oct 19 '18 at 07:40
  • Where did you close the ``? – Mickaël Leger Oct 19 '18 at 08:04
  • its only a snipped... the error is here beetween `'=$current_id?>'` need to use " i think but how can i do it? because i use the `''` always. how can i do that like `'.=$current_id?>.'` is not correct. – AndyDE Oct 19 '18 at 08:24
  • Coming back to this question after the weekend, thank you for the more detailed explanation of the location of the error, but it would have helped to post the resultant HTML in the first place. Anyway, since you are in a string in PHP, you don't need the `= ?>` stuff; `id='$current_id'` will suffice, or the slightly longer `"...id='" . $current_id . "'..."`. – Ken Y-N Oct 21 '18 at 23:43

1 Answers1

0

now it work. What i have to do now:

 $ccid = "#$current_id";
 $ccid2 = "$current_id"; 

And then i have put the variables inside of ID and Href Like this:

href='".$ccid."'
id='".$ccid2."'

That fixxed this problem. Thanks to all!

AndyDE
  • 1
  • 3