简体   繁体   中英

How do I loop one button in a while loop and give it different id's in each iteration?

I need the button id in the table to change however many times the while loop occurs. The button works when the loop occurs one time, once it loops more than once then the buttons stop working. How should I format this php code so the buttons will work after one loop. Also the button is just a drop down with four functions in it.

I have tried having a variable id in the divs, dropdown, and button that increments and it still doesn't work. I put the incrementing variable in the Details button to see of it was working. After doing research my hypothesis was that since the id is incrementing by one in each loop that means all the button ids will be different and the buttons that are echoed out will function independently of each other but that isn't the and they don't function at all.

$c=1;
while($row =  sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_ASSOC) ){

$button = <div id='".$c."' class='dropdown'>
<button value='".$c."' id='".$c."' type='button' class='btn btn-primary 
dropdown-toggle' data-toggle='dropdown'> $c Details <span class='caret'> 
</span></button>
<ul value='".$c."' id='".$c."' class='dropdown-menu'>
<li><a href='#' id='action1'><span class ='glyphicon glyphicon-th-list 
glyph-to-left'></span> Children</a></li>
<li><a href='#' id='action2'><span class ='glyphicon glyphicon-tasks glyph- 
 to-left'></span> Pets</a></li>
 <li><a href='#' id='action3'><span class ='glyphicon glyphicon-list-alt 
 glyph-to-left'></span> Parents</a></li>
 <li><a href='#' id='action4'><span class ='glyphicon glyphicon-cloud- 
 download glyph-to-left'></span> Grandparents</a></li>
 </ul>
 </div>
 </div>;

 echo "<tr><td>". $row['Username'] ."</td><td>". $row['asset id'] ." 
 </td><td>" . $row['Firstname'] ."</td><td>" . $row['Lastname'] ."</td> 
 <td>" . $row['asset type'] ."</td><td>". 
 $row['Date']->format('M-d-Y')."</td><td>" . $row['Marital Status']. " 
 </td><td>" . $row['operational status']. "</td><td>". 
 $row['Yearly Income'] ."</td><td>" . $row['Taxes']. " 
 </td><td>". $button. "</td></tr>";

有一个计数器变量,并将其值作为字符串包含在ID的末尾

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM