473,236 Members | 1,691 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,236 software developers and data experts.

printing html table elements inside php script

I would like to print a table, using a while loop to insert as many
blank text fields as players specified by the user. How do I put html
inside a php loop.
This is what I have....

<body>
<form name="results" method="post">
Number of players:<input type ="textarea" name="number_players">
<input name="Submit" type="submit"></form>
<?php
$x=0;
while ($x<$number_players){
print ("Place : $x<br>");
$variable ="<input type="textarea" name=$x>";
print($variable);
$x++;
}
</body>
(I did a search, but didn't understand the answer I found)

Jul 17 '05 #1
4 2804
*** go****@charliefortune.com wrote/escribió (10 Jun 2005 08:50:45 -0700):
How do I put html inside a php loop.
That's explained in the very first chapter of the manual:

http://php.grn.es/manual/en/introduction.php

There you have a link to further explanations:

http://php.grn.es/manual/en/language...syntax.phpmode
<?php
$x=0;
while ($x<$number_players){
print ("Place : $x<br>");
$variable ="<input type="textarea" name=$x>";
print($variable);
$x++;
}
</body>


Didn't you get a parse error?
--
-- Álvaro G. Vicario - Burgos, Spain
-- http://bits.demogracia.com - Mi sitio sobre programación web
-- Don't e-mail me your questions, post them to the group
--
Jul 17 '05 #2


go****@charliefortune.com wrote (in part):
I would like to print a table, using a while loop to insert as many
blank text fields as players specified by the user. How do I put html
inside a php loop.
This is what I have....

<body>
<form name="results" method="post">
Number of players:<input type ="textarea" name="number_players">
<input name="Submit" type="submit"></form>
<?php
$x=0;
while ($x<$number_players){
print ("Place : $x<br>");
$variable ="<input type="textarea" name=$x>";
print($variable);
$x++;
}
</body>


You almost have it right. Here's one way of doing what you want.
<?
$tmp = array();
$tmp[] = '<form action="' . $_SERVER['PHP_SELF'] . '" name="results"
method="post">';
$tmpv = (isset($_POST['number_of_players']))?' value="' .
$_POST['number_of_players'] . '"':'';
$tmp[] = 'Number of players: <input type="text"
name="number_of_players"' . $tmpv . '>';
if (isset($_POST['number_of_players']))
for ($i=0;$i<$_POST['number_of_players'];$i++)
$tmp[] = 'Place ' . $i . ': <input type="text" name="place[' .
$i . ']">';
$tmp[] = '<input type="submit" name="submit" value="Submit">';

echo implode("<br>\n",$tmp)."\n";
?>

Some explanation.

The first time a user brings up the form, just input box labeled
"Number of players" is displayed. When the user fills it in and presses
"submit", the form is redisplayed with the appropriate number of input
boxes.

More code is needed for this form to do anything else and I have done
no error checking, such as making sure that the input is really a
number.

Ken

Jul 17 '05 #3
go****@charliefortune.com wrote:
I would like to print a table, using a while loop to insert as many
blank text fields as players specified by the user. How do I put html
inside a php loop.
This is what I have....

<body>
<form name="results" method="post">
Number of players:<input type ="textarea" name="number_players">
<input name="Submit" type="submit"></form>
<?php
$x=0;
while ($x<$number_players){
print ("Place : $x<br>");
$variable ="<input type="textarea" name=$x>";
print($variable);
$x++;
}
</body>
(I did a search, but didn't understand the answer I found)

I recently saw a post saying this was bad form or something, but it's
what I always do. You can use open and close tags all you want, so I
close php and just put in the HTML (echoing any Php variables):

<?php
$x=0;
while ($x<$number_players) {
?>
/ Place : <?= $x ?> <br>
<input type="textarea" name=<?= $x ?>>

/<?php
$x++;
}
?>
</body>

I find that this makes the script much more readable and it's easier to
place correct and well structured HTML.

BTW, there is no input type=textarea. It's type=text or if you really
meant a textarea, they have their own tags <textarea
name=textareaname></textarea>

--
*****************************
Chuck Anderson • Boulder, CO
http://www.CycleTourist.com
Integrity is obvious.
The lack of it is common.
*****************************
Jul 17 '05 #4
Chuck Anderson wrote:
go****@charliefortune.com wrote:
I would like to print a table, using a while loop to insert as many
blank text fields as players specified by the user. How do I put html
inside a php loop.
This is what I have....

<body>
<form name="results" method="post">
Number of players:<input type ="textarea" name="number_players">
<input name="Submit" type="submit"></form>
<?php
$x=0;
while ($x<$number_players){
print ("Place : $x<br>");
$variable ="<input type="textarea" name=$x>";
print($variable);
$x++;
}
</body>
(I did a search, but didn't understand the answer I found)


I recently saw a post saying this was bad form or something, but it's
what I always do. You can use open and close tags all you want, so I
close php and just put in the HTML (echoing any Php variables):

<?php
$x=0;
while ($x<$number_players) {
?>
/ Place : <?= $x ?> <br>
<input type="textarea" name=<?= $x ?>>

/<?php
$x++;
}
?>
</body>

I find that this makes the script much more readable and it's easier to
place correct and well structured HTML.

BTW, there is no input type=textarea. It's type=text or if you really
meant a textarea, they have their own tags <textarea
name=textareaname></textarea>

Not sure how those slashes (/) got there, but they're not supposed to be
there.

<?php
$x=0;
while ($x<$number_players) {
?>
Place : <?= $x ?> <br>
<input type="textarea" name=<?= $x ?>>

<?php
$x++;
}
?>
</body>
--
*****************************
Chuck Anderson • Boulder, CO
http://www.CycleTourist.com
Integrity is obvious.
The lack of it is common.
*****************************
Jul 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: Kevin Lyons | last post by:
Hello, I am trying to get my select options (courses) passed correctly from the following URL: http://www.dslextreme.com/users/kevinlyons/selectBoxes.html I am having difficulty getting the...
2
by: Henrik J?nsson | last post by:
Hi! I have a problem that I can't find a solution to. I have a perl script that generates reports from our NCR system for our intranet. The NCRs are displayed on a single html page. Now I...
5
by: Mark Preston | last post by:
Admission first - I don't actually have a problem here but have noticed that a lot of people have been asking similar questions and getting very varied answers. What I've done is to sort of...
10
by: Peter Kirk | last post by:
Hi there can someone please help me with creating dynamic content in a table? For example, see the below javascript and html - why is a new row not created in the table when I click the button?...
5
by: ojvm | last post by:
ok. thanks again for the time spend reading this. this code adds 2 controls in html form but it places in top of the form. i want this control1 control2 control1 control2 control1 ...
16
by: cyranoVR | last post by:
This is the approach I used to automate printing of Microsoft Access reports to PDF format i.e. unattended and without annoying "Save As..." dialogs, and - more importantly - without having to use...
2
by: justplain.kzn | last post by:
Hi, I have a table with dynamic html that contains drop down select lists and readonly text boxes. Dynamic calculations are done on change of a value in one of the drop down select lists. ...
8
by: Neo Geshel | last post by:
Greetings. BACKGROUND: My sites are pure XHTML 1.1 with CSS 2.1 for markup. My pages are delivered as application/xhtml+xml for all non-MS web clients, and as text/xml for all MS web...
21
by: array7 | last post by:
I have been reading a lot of archived threads about "page-break- inside: avoid" not supported by IE5, IE6 IE55, IE7 and Firefox (Mozilla), which creates a really unpleasant-looking printout with...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.