I have a little problem with my PHP while loop. I am looping out all the available membership packages (and it's details) from my database.
My code is like this:
<?php
while($mp = mysql_fetch_assoc($s)):
?>
<tr class="hover">
<td class="name" width="30%"><?php echo $mp['membershipname']; ?></td>
<td class="price" width="30%">$<span><?php echo $mp['ap_price']; ?></span>/<span><?php echo $mp['duration']; ?></span> days.</td>
<?php if($userdata['membership']>$mp['membershipid']): ?>
<td width="40%" class="purchase"></td>
<?php else: ?>
<td width="40%" class="purchase" >
<a href="#" id="upg<?php echo $mp['id']; ?>" class="click cgreen inline">Pricing</a>
</tr>
<?php endif; ?>
<div style='display:none'>
<div id='inline_content' style='padding:10px; background:#fff;'>
<div style="text-align:center;font-weight:bold">Please select your payment method:</div>
<div style="text-align:center">
<br />
<?php
if($sdata['allow_paypal'] == 1 && $mp['pp_price']>0 && $userdata['paypal']!=""): ?>
<form action="https://www.paypal.com/cgi-bin/webscr" method="post" style="float:left;" >
<input type="submit" name="submit" class="click cblue" value="PayPal - $<?php echo $mp['pp_price']; ?>">
</form>
<?php endif;
if($sdata['allow_alertpay'] == 1 && $mp['ap_price']>0 && $userdata['alertpay']!=""):
//Do not change any input fields, OTHER than return URL (if needed)
?>
<form method="post" name="a开发者_StackOverflow社区p" action="https://www.alertpay.com/PayProcess.aspx" style="float:right;" >
<input type="submit" name="submit" class="click cgreen" value="AlertPay - $<?php echo $mp['ap_price']; ?>" />
</form>
<?php
endif; ?>
</div>
</div>
</div>
<script>
$(document).ready(function(){
$("#upg<?php echo $mp['id']; ?>").colorbox({inline:true, width:"30%",href:"#inline_content"});
});
</script>
<?php endwhile; ?>
As you can see in the above code, I am doing a while loop.
My problem is that the $mp['pp/ap_price']
inside the #inline_content is not looping. It only take the price from the first row. Although, it is looping in the table.
What's the issue here? I tried to do another loop inside the #inline_content, but it didn't work.
HTML IDs should be unique to one DOM element.
You have a DOM element #inline_content
for every record in your database query result. Then, when you try to use Javascript to display them all, only one is displayed because they all have the same ID.
HTML and Javascript are not aware of your PHP loop.
Consider using a class
attribute instead of an id
attribute.
精彩评论