tags:

views:

56

answers:

6
$sun=$_POST["name"];
print "<ul>";
for(0;0<$sun;$sun++)
{
 print  "the value is".$sun."<input type="text" name="nam">";
}
print "</ul>";

is it correct............?if it is false ,plz solve correct answer.....

+1  A: 

If you're just worried about concatenation, you can do this:

print "<li>the value is $sun <input type=\"text\" name=\"nam\" /></li>";

PHP supports interpolation so you can use the variable in your print statement.

I'm not sure what your loop is trying do do though.

Vivin Paliath
+1  A: 

Not quite sure what you're trying to do; Your concatenation part was correct. Your code was probably giving errors. I changed print to echo and backslashed a few quotes. Oh, and added a space after "the value is":

$sun=$_POST["name"];
echo "<ul>";
for($x=0;$x<$sun;$x++)
{
 echo  "the value is ".$sun."<input type=\"text\" name=\"nam\">";
}
echo "</ul>";
PlagueEditor
Just a note, consecration is a religious ceremony... some people like PHP that much, but I think you mean concatenation :)
Alex JL
Should that read $i++ cos $sun++ would make it as pointless as the OP's original suggestion.
+2  A: 
$sun=$_POST["name"];
print "<ul>";
for($i=0;$i<$sun;$i++)
{
    print  "<li>the value is $i<input type=\"text\" name=\"nam\" /></li>";
}
print "</ul>";

Is that what you mean?

MrSoundless
Should that read `$i++` cos `$sun++` would make it as pointless as the OP's original suggestion.
Comparing an int, i to a string, $sun, doesn't really make sense under any condition whatsoever.
Alex JL
A: 

It is false :-) at least the for statement is really suspect, sounds like it'll never end. The other problem is that you do not check the posted value, it might just be anything but an integer. There are also typos like a space missing after "is". There are probably even more problems... I suspect you are desperately trying to solve some homework...

jdehaan
+2  A: 

Since i don't know what you're trying to do, i thought id just point out what i see wrong:

  • $sun."<input type=\"text\" name=\"name\">";
  • This thing wont even loop unless your init is > 0
  • Once it loops, it will be an infinate loop.
Babiker
A: 

If the question is about concatenation, there are a few ways to put a variable into a string in PHP.

//this would almost work fine as, you had it:
print  "the value is".$sun."<input type="text" name="nam">";

EXCEPT the same quotes are used for type="text" and name="nam" as for the string itself. PHP interprets that to mean the end of the string, and then it sees the random word 'text' and will throw an error. Either escape them like name=\"nam\" to make the quotes not be taken literally by the parser, or name='nam'.

But there is no reason to concatenate if you are using double quotes... double quotes are used for strings that require variable interpolation, so just put the var right in there like

print  "the value is $sun<input type='text' name='nam'>";

With concatenation instead,

print  'the value is '.$sun.'<input type="text" name="nam">';

or

print  'the value is '.$sun.'<input type=\'text\' name=\'nam\'>';

Then, you might want to check what the steps in a for loop mean. From the manual

for loops are the most complex loops in PHP. They behave like their C counterparts. The syntax of a for loop is:

for (expr1; expr2; expr3){
  statement
  }

- The first expression (expr1) is evaluated (executed) once unconditionally at the beginning of the loop.

- In the beginning of each iteration, expr2 is evaluated. If it evaluates to TRUE, the loop continues and the nested statement(s) are executed. If it evaluates to FALSE, the execution of the loop ends.

- At the end of each iteration, expr3 is evaluated (executed). 

The loop you have is kind of backwards. You wouldn't want to do just 0 as your first part, or 0<$sun in the middle; Do you even need a loop right there?

Alex JL