PHP Variable Passing in Foreach on same page

Posted by tooly228 on Stack Overflow See other posts from Stack Overflow or by tooly228
Published on 2013-06-28T22:01:04Z Indexed on 2013/06/28 22:21 UTC
Read the original article Hit count: 109

Filed under:
|
|

I've been struggling this for a while and I simply can't figure this out. Here is my code:

<?php
foreach($list as $id =>$name) {
echo("<td style=\"vertical-align:middle;\">
      <a href=\"item=$id#confirm\" role=\"button\" data-toggle=\"modal\">
      Buy</a></td></tr>");
}?>

<html>
<div class="modal small hide fade" id="confirm" tabindex="-1" 
      role="dialog" aria-   labelledby="myModalLabel" aria-hidden="true">
<a href="redeem.php?item=<?php echo $id; ?>"><button class="btn btn-danger">
      Buy</button></a></div>

The main issue here is that the $id from the foreeach is not the same as the $id in the div class link. Instead the link is the end value of the foreach list.

© Stack Overflow or respective owner

Related posts about php

Related posts about div