0

Hi There I am hoping that someone can help me with this php issue.

i would like to get the number into the form from this Loop function

for($i = 1; $i <= 100; $i++)
{
    echo '<textarea name="textarea" id="textarea" cols="100" rows="10">'.spin($string, false).'</textarea>';
    echo '<textarea name="textarea" id="textarea" cols="100" rows="10">'.spin($string, false).'</textarea>';
}

any idea on how I can implement it as to number the textarea(s) from 1 to 100

Thanks

1
  • Hi Zneak - yes similar to an id tag... if i can print out like 1 2 3 4 5 6 7 etc... up to 100 Commented Jul 17, 2010 at 17:31

1 Answer 1

4

Use string concatenation ., a number will be automatically converted to a string:

for($i = 1; $i <= 100; $i++)
{
    echo '<textarea name="textarea" id="textarea' . $i . '" cols="100" rows="10">'.spin($string, false).'</textarea>';
}

Or if you want to actually display the number:

for($i = 1; $i <= 100; $i++)
{
    echo $i . '. <textarea name="textarea" id="textarea' . $i . '" cols="100" rows="10">'.spin($string, false).'</textarea>';
}

If this is not what you want to have to clarify what you want.


Note: An ID has to be unique for any HTML element. In your code, you generate 100 textareas with the same ID.

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks Felix this is exactly what I looked for... I tried to do it as .i. but not with the $ :-)...
@Gerald Ferreira: You're welcome. Variables always start with $ ;)
Note: An ID has to be unique for any HTML element. In your code, you generate 100 textareas with the same ID. I am using asp but needed a php function. Now I can submit the 100 texarea's to my php and pick up the values there!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.