473,666 Members | 2,131 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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_pl ayers">
<input name="Submit" type="submit"></form>
<?php
$x=0;
while ($x<$number_pla yers){
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 2822
*** go****@charlief ortune.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_pla yers){
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 programacin web
-- Don't e-mail me your questions, post them to the group
--
Jul 17 '05 #2


go****@charlief ortune.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_pl ayers">
<input name="Submit" type="submit"></form>
<?php
$x=0;
while ($x<$number_pla yers){
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_play ers']))?' value="' .
$_POST['number_of_play ers'] . '"':'';
$tmp[] = 'Number of players: <input type="text"
name="number_of _players"' . $tmpv . '>';
if (isset($_POST['number_of_play ers']))
for ($i=0;$i<$_POST['number_of_play ers'];$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****@charlief ortune.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_pl ayers">
<input name="Submit" type="submit"></form>
<?php
$x=0;
while ($x<$number_pla yers){
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_pla yers) {
?>
/ 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=textareana me></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****@charlie fortune.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_pl ayers">
<input name="Submit" type="submit"></form>
<?php
$x=0;
while ($x<$number_pla yers){
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_pla yers) {
?>
/ 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=textarean ame></textarea>

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

<?php
$x=0;
while ($x<$number_pla yers) {
?>
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
6533
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 courses to pass the correct option value and then be displayed at the following URL: http://www.dslextreme.com/users/kevinlyons/selectResults.html I am passing countries, products, and courses. The first two display
2
3261
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 would like to have a print button next to each NCR so that the users can press the print button and only the nearest NCR is printed. The problem is how can I select a single NCR in the page. I can search
5
2213
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 "compile the questions" into a theoretical problem to see what people think should be done to solve it. Maybe it will be a worthwhile discussion, but more importantly maybe it will find out the very best way to sort this kind of problem out so that...
10
2287
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? (I am using Internet Explorer 6). <html> <head> <title>TEST</title> <script language="javascript">
5
1891
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 control2
16
48867
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 a commercial program such as Adobe Acrobat and its associated API. The technique uses Ghostscript and Redirection Port Monitor - two free programs for creating PDF documents provided free by Russell Lang. The actual automation requires VBA...
2
2112
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. Using Safari,my first iteration the script works fine ( indicating that there are 33 form variables ). When trying another dropdown select value, the
8
5887
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 clients (Internet Explorer). My flash content was originally brought in via the “flash satay” method, but I have since used some server-side magic do deliver one <objecttag
21
4316
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 broken table rows. I wonder if after all these years in discussion anyone had come up with a trick using maybe some combination of "page-break-before", "page-break-after" or div properties that would prevent the situation.
0
8444
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look ! Part I. Meaning of...
0
8356
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8781
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8551
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8639
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5664
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4198
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2771
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1775
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.