473,386 Members | 1,630 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,386 software developers and data experts.

for loop and formatting its output

HelloIn the following snippet of code x text fields are generated. I can
include <brat the end to split them onto separate lines, but how do I
modify the code to have two text fields on each line?

for ($x = 1; $x <= $ansperquest; $x++){
echo "Type Answer ".$x ?><input name="<?php echo 'ansE'.$x; ?>" size="30"
type="text"><?php
}

Thanks
Ian
Sep 23 '06 #1
2 1169

"mantrid" <ia********@virgin.netwrote in message
news:Sr*******************@newsfe2-gui.ntli.net...
HelloIn the following snippet of code x text fields are generated. I can
include <brat the end to split them onto separate lines, but how do I
modify the code to have two text fields on each line?

for ($x = 1; $x <= $ansperquest; $x++){
echo "Type Answer ".$x ?><input name="<?php echo 'ansE'.$x; ?>"
size="30"
type="text"><?php
}

Thanks
Ian


ok
i got it

for ($x = 1; $x <= $ansperquest; $x++){
if ($x % 2 == 0 ){
echo "Type Answer ".$x ?><input name="<?php echo 'ansE'.$x; ?>"
size="30" type="text"><br><?php
}else{
echo "Type Answer ".$x ?><input name="<?php echo 'ansE'.$x; ?>"
size="30" type="text"><?php
}
}
Sep 23 '06 #2
"mantrid" <ia********@virgin.netwrote in message
news:EB*****************@newsfe3-gui.ntli.net...
>
"mantrid" <ia********@virgin.netwrote in message
news:Sr*******************@newsfe2-gui.ntli.net...
>HelloIn the following snippet of code x text fields are generated. I can
include <brat the end to split them onto separate lines, but how do I
modify the code to have two text fields on each line?

for ($x = 1; $x <= $ansperquest; $x++){
echo "Type Answer ".$x ?><input name="<?php echo 'ansE'.$x; ?>"
size="30"
>type="text"><?php
}

Thanks
Ian



ok
i got it

for ($x = 1; $x <= $ansperquest; $x++){
if ($x % 2 == 0 ){
echo "Type Answer ".$x ?><input name="<?php echo 'ansE'.$x; ?>"
size="30" type="text"><br><?php
}else{
echo "Type Answer ".$x ?><input name="<?php echo 'ansE'.$x; ?>"
size="30" type="text"><?php
}
}

Or better yet, just use the modulo test for printing the <br>

<?php for ($x = 1; $x <= $ansperquest; $x++){ ?>
Type Answer <?php echo $x ?>
<input name="ansE<?php echo $x; ?>" size="30" type="text">
<?php if ($x % 2 == 0 ) echo '<br>'; ?>
<?php } ?>

--
"Ohjelmoija on organismi joka muuttaa kofeiinia koodiksi" - lpk
http://outolempi.net/ahdistus/ - Satunnaisesti päivittyvä nettisarjis
sp**@outolempi.net || Gedoon-S @ IRCnet || rot13(xv***@bhgbyrzcv.arg)
Sep 25 '06 #3

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

Similar topics

6
by: shoo | last post by:
Any one know how to do this? thank Write a simple text-formatting program that produces neatly printed output from input text containing embedded command lines that determine how to format the...
8
by: Mike MacSween | last post by:
tblCourses one to many to tblEvents. A course may have an intro workshop (a type of event), a mid course workshop, a final exam. Or any combination. Or something different in the future. At...
6
by: shoo | last post by:
Any one know how to do this? thank Write a simple text-formatting program that produces neatly printed output from input text containing embedded command lines that determine how to format the...
7
by: ilona | last post by:
Hi all, I store phone numbers in the database as 123447775665554(input mask is used for input, and some numbers have extensions), and I also know from db if the number is Canadian, US, or some...
8
by: Vinay Jain | last post by:
Hi.. I am newbe in postgresql so please help me though the question may be very easy to answer.. Is there any formatting function to get output with fix lengths..for example my query is.. schema...
14
by: morpheus | last post by:
Hi Group, May I ask the following? for (i=0; (c=getchar()) != EOF && c != '\n'; ++i) line=c; What I am finding is that when c == '\n' is true, the loop is terminated but i is still...
9
by: sck10 | last post by:
Hello, I have a page with an ImageButton that is used to redirect to another page. When the page first opens, everything looks as expected. However, when I click on the image, the new page...
19
by: vamshi | last post by:
Hi all, This is a question about the efficiency of the code. a :- int i; for( i = 0; i < 20; i++ ) printf("%d",i); b:- int i = 10;
6
by: Rafael Olarte | last post by:
The goal of this project is to output the following information as follows: 34.5 38.6 4.1 42.4 3.8 close 46.8 4.4 big change. The values of the first colunm are obtain from a file...
1
by: AJG | last post by:
Hi there. I am using a library called SOCI that has a method to set a stream which it uses to log SQL queries. The signature is as follows: void setLogStream(std::ostream *s); This works great...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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:
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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...
0
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...

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.