我正在尝试创建类似于拍卖/出价表/表单的内容。 如果值(当前出价)为1000,我正在尝试创建一个允许其他用户以500为间隔出价的选择框,因此对于此示例,结果将如下:
Current Bid: 1000
Buy Now: 5000
<select class="form-control">
<option value="1500">1500</option>
<option value="2000">2000</option>
<option value="2500">2500</option>
<option value="3000">3000</option>
<option value="3500">3500</option>
<option value="4000">4000</option>
<option value="4500">4500</option>
</select>
这样的事情:
<?php
$query = $db->query('SELECT * FROM auctions WHERE available = 1 LIMIT 1');
$num = $query->num_rows;
if($num > 0) {
echo '<select class="form-control">';
foreach($query as $row) {
$currentBid = $row['currentBid']; // 1000
$buyNow = $row['buyNow']; // 5000
$bids = ?? // this is where I am stuck, how can I make the difference between $currentBid and $buyNow show as options divided by 500's
echo '
<option value="'.$bids.'">'.$bids.'</option>
';
}
echo '</select>';
}
else {
echo "No auctions available";
}
?>
答案 0 :(得分:1)
...
$currentBid = $row['currentBid'];
$buyNow = $row['buyNow'];
...
$options = '';
for($p = $currentBid + 500; $p <= $buyNow; $p += 500) {
$options .= '<option value="'.$p.'">'.$p.'</option>';
}