<?php
$i = 0;
while($i<=10 ){
echo '<label for=""></label><select name="comp'. $i++ .'></select><br>';
}
?>
I'm using this code for adding 10 select boxes on the html page, but instead only 5 select boxes are appearing, don't know why??
Is there any explanation, or my php is just drunk.....
echo '<label for=""></label><select name="comp'. $i++ .'"></select><br>';
I think you are missing one double qoutes
'"></select><br>';
^
You missed double quota here:
<select name="comp'. $i++ .'>
^------
it should be:
<select name="comp'. $i++ .'">
Your loop is fine and the code should run through 10 times, but you're missing a double quote on your echo line after $i++.
It should read something like:
echo '<label for=""></label><select name="comp'. $i++ .'"></select><br>';
That said, you might be little better off for clarity swapping out your while loop with a for:
<?php
for($i = 0; $i < 10; $i++){
echo '<label for=""></label><select name="comp'. $i .'"></select><br>';
}
?>
The following code works as desired :
<?php
$i = 0;
while($i<=10 ){
echo '<label for=""></label>';
echo '<select name="comp'. $i++ .'"></select>';
echo '<br>';
}
?>
you missed the '"' after $i++ in second echo statement