473,382 Members | 1,400 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,382 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 2808
*** 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: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

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.