开发者

unknown input name check

How can开发者_高级运维 I check the inputs below:

<?php 
  for($i = 0; $i < 9; $++){
echo "<input type='text' name='{$i}[qty]'>";
}
?>

now my qustion is how can I check the unknown input name if the value is bigger than 10 or smaller than 1?


You did explain too little about your usage or the rest of your form structure. But generally you don't want to name the fields not with a number first, but the other way around:

print "<input type='text' name='qty[$i]'>";
   // would also work with just 'qty[]' in most cases

This way it becomes a very simple indexed array upon receival in PHP which you can traverse with:

$_REQUEST["qty"][$i++]
   // or
foreach ($_REQUEST["qty"] as $i => $qty) {

This way you wont miss either larger indexes than 10 or those below 0 - although you really should avoid negative indexes. (Not because it doesn't work, but it's probably an unoptimal methodology.)


If you use these qty form fields of part of another group, then you want to use the same array[$i] naming for all of them. Thus when you foreach over the loop you can access all in groups: $_REQUEST["qty"][$i] belongs to $_REQUEST["product"][$i] for example.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜