HELLO, 我有一个html选择列表,我想要:选定的数字是一个给定的值$content->number
,最大值是$content->product_type->stock_2
如果它小于5,或5,如果它是大于5。html选择列表选择的项目和最大值可以选择
现在我有:
<select class="number" name="number">
<? $max = $content->product_type->stock_2 > 5 ? 5 : $content->product_type->sale_stock; ?>
<option value="<?= $content->number ?>"><?= $content->number; ?> </option>
<? for ($i = 1; $i <= $max; $i++):?>
<option <?php if($content->product_type->stock_2 == $i) echo 'selected="selected"' ;?> value="<?= $i ?>"><?= $i; ?></option>
<? endfor; ?>
</select>
但它显示我两次选定值$content->number
。我确定我在某个地方犯错。
有什么建议吗? 谢谢!
达纳是你的问题与此'<? $ max = $ content-> product_type-> stock_2> 5? 5:$ content-> product_type-> sale_stock; “我似乎无法理解整个问题。如果这个'$ content-> product_type-> stock_2> 5'为true,并且您希望它成为这个'$ content-> product_type-> sale_stock',如果$ content-> product_type-> stock_2> 5'是错误的,对吧? – Bastardo 2011-04-26 13:10:03
正是:)这就是我想要的 – dana 2011-04-26 13:23:51
:)但在你的问题中,你说**的最大值是$ content-> product_type-> stock_2,如果它小于5 **我的意思是你需要写一个2在'<?的结尾$ max = $ content-> product_type-> stock_2> 5? 5:$ content-> product_type-> sale_stock; ?>'不是吗? – Bastardo 2011-04-26 14:04:12