I'm trying to while loop using a flat txt file and write the values out
into a form. I have 50-58 values to echo. Am I going to have to echo
each line of html. Or is there a way to make this work between the php.
Right now it wants to write the whole table over and over. Is my logic
screwed up? I am not a programmer as such but can get by. I have
something like this which is an abbreviated version. Any help would be
appreciated.
Thanks,
Patrick
<html>
<head>
<?
$filename = "C10AB_precruis e.log";
$larray = file($filename) ;
?>
</head>
<body>
<?
$i=0;
while ($i <= 60)
{
?>
<form method="post" action="precmlo g.php">
<table width="800" cellpadding="5" cellspacing="0" border="0">
<tr>
<td width="40%">
Log sheet completed by:<br> <input class="inform" type="text"
size="30" name="person" value="<?php echo $larray[$i]; ?>"><br>
</td>
</tr>
<tr>
<td>
Cruise name/number:<br> <input class="inform" type="text" size="30"
name="cruisenum " value="<?php echo $larray[$i]; ?>"><br>
</td>
</tr>
<tr>
<td>
Ship name:<br> <input class="inform" type="text" size="30"
name="shipname" value="<?php echo $larray[$i]; ?>"><br>
</td>
</tr>
</table>
<input class="button" type="submit" value="Submit">
</form>
<?
}
$i++;
?>
</body>
</html>
--
Patrick A. Smith Assistant System Administrator
Ocean Circulation Group – USF - College of Marine Science http://ocgweb.marine.usf.edu Phone: 727 553-3334
The trouble with doing something right the first time is that nobody
appreciates how difficult it was. - La Rochefoucauld 5 1519
Patrick wrote: I'm trying to while loop using a flat txt file and write the values out into a form. I have 50-58 values to echo. Am I going to have to echo each line of html. Or is there a way to make this work between the php. Right now it wants to write the whole table over and over. Is my logic screwed up? I am not a programmer as such but can get by. I have something like this which is an abbreviated version. Any help would be appreciated.
Thanks, Patrick
If your input file looks something like this:
fred, Barbados/123, Titanic
sally, Turks/Caicos, Mary Celleste
then the following code will help you get started:
<html>
<head>
</head>
<body>
<?php
$filename = "test.log";
if( ! ($fd = fopen($filename , "r")) ) {
echo "Cannot open $filename for read<br>\n";
exit;
}
while( $line = fgets($fd, 80) ) {
$values = explode(',', $line); // assumes comma-separated values
?>
<form method="post" action="precmlo g.php">
<table width="800" cellpadding="5" cellspacing="0" border="0">
<tr>
<td width="40%">
Log sheet completed by:<br> <input class="inform" type="text"
size="30" name="person" value="<?php echo $values[0]; ?>"><br>
</td>
</tr>
<tr>
<td>
Cruise name/number:<br> <input class="inform" type="text"
size="30" name="cruisenum " value="<?php echo $values[1]; ?>"><br>
</td>
</tr>
<tr>
<td>
Ship name:<br> <input class="inform" type="text" size="30"
name="shipname" value="<?php echo $values[2]; ?>"><br>
</td>
</tr>
</table>
<input class="button" type="submit" value="Submit">
</form>
<?php
}
fclose($fd);
?>
</body>
</html>
-david-
David Haynes wrote: Patrick wrote:
I'm trying to while loop using a flat txt file and write the values out into a form. I have 50-58 values to echo. Am I going to have to echo each line of html. Or is there a way to make this work between the php. Right now it wants to write the whole table over and over. Is my logic screwed up? I am not a programmer as such but can get by. I have something like this which is an abbreviated version. Any help would be appreciated.
Thanks, Patrick
If your input file looks something like this: fred, Barbados/123, Titanic sally, Turks/Caicos, Mary Celleste
then the following code will help you get started: <html> <head> </head> <body> <?php $filename = "test.log"; if( ! ($fd = fopen($filename , "r")) ) { echo "Cannot open $filename for read<br>\n"; exit; }
while( $line = fgets($fd, 80) ) { $values = explode(',', $line); // assumes comma-separated values ?>
<form method="post" action="precmlo g.php">
<table width="800" cellpadding="5" cellspacing="0" border="0"> <tr> <td width="40%"> Log sheet completed by:<br> <input class="inform" type="text" size="30" name="person" value="<?php echo $values[0]; ?>"><br> </td> </tr> <tr> <td> Cruise name/number:<br> <input class="inform" type="text" size="30" name="cruisenum " value="<?php echo $values[1]; ?>"><br> </td> </tr>
<tr> <td> Ship name:<br> <input class="inform" type="text" size="30" name="shipname" value="<?php echo $values[2]; ?>"><br> </td> </tr> </table>
<input class="button" type="submit" value="Submit"> </form>
<?php } fclose($fd); ?> </body> </html>
-david-
Hi
Thanks for the reply. Yes I can already do that ie.
$values[1]...[2]...[3], and no the file is not comma delimited. It is
delimited by a new line as some of the values are text area inputs. What
I want to be able to do is have the while iterate to the next value so
that any changes in the text file or the originating form that writes
the text file will not require me to go into this one and change all the
numbers.
Patrick
--
Patrick A. Smith Assistant System Administrator
Ocean Circulation Group – USF - College of Marine Science http://ocgweb.marine.usf.edu Phone: 727 553-3334
The trouble with doing something right the first time is that nobody
appreciates how difficult it was. - La Rochefoucauld
Patrick wrote: David Haynes wrote: Patrick wrote:
I'm trying to while loop using a flat txt file and write the values out into a form. I have 50-58 values to echo. Am I going to have to echo each line of html. Or is there a way to make this work between the php. Right now it wants to write the whole table over and over. Is my logic screwed up? I am not a programmer as such but can get by. I have something like this which is an abbreviated version. Any help would be appreciated.
Thanks, Patrick
If your input file looks something like this: fred, Barbados/123, Titanic sally, Turks/Caicos, Mary Celleste
then the following code will help you get started: <html> <head> </head> <body> <?php $filename = "test.log"; if( ! ($fd = fopen($filename , "r")) ) { echo "Cannot open $filename for read<br>\n"; exit; }
while( $line = fgets($fd, 80) ) { $values = explode(',', $line); // assumes comma-separated values ?>
<form method="post" action="precmlo g.php">
<table width="800" cellpadding="5" cellspacing="0" border="0"> <tr> <td width="40%"> Log sheet completed by:<br> <input class="inform" type="text" size="30" name="person" value="<?php echo $values[0]; ?>"><br> </td> </tr> <tr> <td> Cruise name/number:<br> <input class="inform" type="text" size="30" name="cruisenum " value="<?php echo $values[1]; ?>"><br> </td> </tr>
<tr> <td> Ship name:<br> <input class="inform" type="text" size="30" name="shipname" value="<?php echo $values[2]; ?>"><br> </td> </tr> </table>
<input class="button" type="submit" value="Submit"> </form>
<?php } fclose($fd); ?> </body> </html>
-david- Hi
Thanks for the reply. Yes I can already do that ie. $values[1]...[2]...[3], and no the file is not comma delimited. It is delimited by a new line as some of the values are text area inputs. What I want to be able to do is have the while iterate to the next value so that any changes in the text file or the originating form that writes the text file will not require me to go into this one and change all the numbers.
Patrick
As long as only your fields are separated by the carriage-returns you
will be all right. If someone sneaks a carriage-return into the text
fields, you will lose your synchronization with the input file. (i.e.
you need to have some trusted form of delimiting the fields)
If you want to use carriage-returns, just replace the while and explode
lines with something like:
while(true) {
if( ! ($line1 = fgets($fd, 80)) ) break;
if( ! ($line2 = fgets($fd, 80)) ) break;
if( ! ($line3 = fgets($fd, 80)) ) break;
and then $value[0] becomes $line1, etc.
BTW the 80 can be replaced with whatever your maxlength is for your text
fields.
-david-
David Haynes wrote: Patrick wrote:
David Haynes wrote:
Patrick wrote:
I'm trying to while loop using a flat txt file and write the values out into a form. I have 50-58 values to echo. Am I going to have to echo each line of html. Or is there a way to make this work between the php. Right now it wants to write the whole table over and over. Is my logic screwed up? I am not a programmer as such but can get by. I have something like this which is an abbreviated version. Any help would be appreciated.
Thanks, Patrick If your input file looks something like this: fred, Barbados/123, Titanic sally, Turks/Caicos, Mary Celleste
then the following code will help you get started: <html> <head> </head> <body> <?php $filename = "test.log"; if( ! ($fd = fopen($filename , "r")) ) { echo "Cannot open $filename for read<br>\n"; exit; }
while( $line = fgets($fd, 80) ) { $values = explode(',', $line); // assumes comma-separated values ?>
<form method="post" action="precmlo g.php">
<table width="800" cellpadding="5" cellspacing="0" border="0"> <tr> <td width="40%"> Log sheet completed by:<br> <input class="inform" type="text" size="30" name="person" value="<?php echo $values[0]; ?>"><br> </td> </tr> <tr> <td> Cruise name/number:<br> <input class="inform" type="text" size="30" name="cruisenum " value="<?php echo $values[1]; ?>"><br> </td> </tr>
<tr> <td> Ship name:<br> <input class="inform" type="text" size="30" name="shipname" value="<?php echo $values[2]; ?>"><br> </td> </tr> </table>
<input class="button" type="submit" value="Submit"> </form>
<?php } fclose($fd); ?> </body> </html>
-david- Hi
Thanks for the reply. Yes I can already do that ie. $values[1]...[2]...[3], and no the file is not comma delimited. It is delimited by a new line as some of the values are text area inputs. What I want to be able to do is have the while iterate to the next value so that any changes in the text file or the originating form that writes the text file will not require me to go into this one and change all the numbers.
Patrick As long as only your fields are separated by the carriage-returns you will be all right. If someone sneaks a carriage-return into the text fields, you will lose your synchronization with the input file. (i.e. you need to have some trusted form of delimiting the fields)
If you want to use carriage-returns, just replace the while and explode lines with something like:
while(true) { if( ! ($line1 = fgets($fd, 80)) ) break; if( ! ($line2 = fgets($fd, 80)) ) break; if( ! ($line3 = fgets($fd, 80)) ) break;
and then $value[0] becomes $line1, etc.
BTW the 80 can be replaced with whatever your maxlength is for your text fields.
-david-
Thanks, I will give that a try.
Patrick
--
Patrick A. Smith Assistant System Administrator
Ocean Circulation Group – USF - College of Marine Science http://ocgweb.marine.usf.edu Phone: 727 553-3334
The trouble with doing something right the first time is that nobody
appreciates how difficult it was. - La Rochefoucauld
"Patrick" <ps****@marine. usf.edu> wrote in message
news:e5******** **@news1.usf.ed u... I'm trying to while loop using a flat txt file and write the values out into a form. I have 50-58 values to echo. Am I going to have to echo each line of html. Or is there a way to make this work between the php. Right now it wants to write the whole table over and over. Is my logic screwed up? I am not a programmer as such but can get by. I have something like this which is an abbreviated version. Any help would be appreciated.
Thanks, Patrick
<html> <head> <? $filename = "C10AB_precruis e.log"; $larray = file($filename) ; ?> </head> <body> <? $i=0; while ($i <= 60) { ?>
<form method="post" action="precmlo g.php">
<table width="800" cellpadding="5" cellspacing="0" border="0"> <tr> <td width="40%"> Log sheet completed by:<br> <input class="inform" type="text" size="30" name="person" value="<?php echo $larray[$i]; ?>"><br> </td> </tr> <tr> <td> Cruise name/number:<br> <input class="inform" type="text" size="30" name="cruisenum " value="<?php echo $larray[$i]; ?>"><br> </td> </tr>
<tr> <td> Ship name:<br> <input class="inform" type="text" size="30" name="shipname" value="<?php echo $larray[$i]; ?>"><br> </td> </tr> </table>
<input class="button" type="submit" value="Submit"> </form>
<? } $i++; ?> </body> </html>
$i++ should be INSIDE the while loop to have effect. Now you don't increase
it so it keeps writing the same form over an over again because $i gets no
bigger and therefore it's always less than 60 thus it becomes an infinite
loop.
fix
<?
} // Loop stops here, $i is never reached.
$i++;
?>
to
<?
$i++; // Now it's inside the loop and is incremented
}
?>
Or even better, use a for-loop instead. That way you'll do all the necessary
loop-control in one logical place:
for($i=0; $i<=60; $i++) { ....
HTH
--
"ohjelmoija on organismi joka muuttaa kofeiinia koodiksi" -lpk sp**@outolempi. net | Gedoon-S @ IRCnet | rot13(xv***@bhg byrzcv.arg) This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Marco |
last post by:
We can read this comment at php.net
>jon
>05-Nov-2003 10:06
>According to my tests, the "do...while" control structure actually seems to
be ~40% faster than the "for" control structure. At least using PHP v4.0.6
>on a few fairly modern Linux machines.
>I used a the getmicrotime function as defined at
http://www.php.net/microtime
|
by: Andrew Koenig |
last post by:
PEP 315 suggests that a statement such as
do:
x = foo()
while x != 0:
bar(x)
be equivalent to
while True:
|
by: RobG |
last post by:
A little while ago I opined that do/while loops are harder to
read than for loops, and therefore I preferred using for loops.
However, it was pointed out that do/while has significant
performance benefits as evidenced by:
<URL:http://www.websiteoptimization.com/speed/10/10-2.html>
(There's a bug in the page, testLoop is both a function name
and the name of the form but if you download the page & rename
|
by: invni |
last post by:
I have a nested while. How do I go from the inner while to the
beginning of the outer while? Can this be done without using goto?
while_1()
{
some codes here
while_2()
{
if true go to the beginning of while_1
}
|
by: Michael B Allen |
last post by:
Should there be any preference between the following logically equivalent
statements?
while (1) {
vs.
for ( ;; ) {
I suspect the answer is "no" but I'd like to know what the consensus is
| |
by: jvb |
last post by:
Hey all,
I figure it's Wednesday, why not put a question up for debate. Beyond
personal preference, is there any benefit (performance or otherwise) to
using one loop over the other? For example, I remember in hearing in
class (many years ago...) that VB compiles For...Next loops as
Do...While loops.
|
by: kydavis77 |
last post by:
i was wondering if anyone could point me to some good reading about the
for and while loops
i am trying to write some programs
"Exercise 1
Write a program that continually reads in numbers from the user and
adds them together until the sum reaches 100. Write another program
that reads 100 numbers from the user and prints out the sum. "
|
by: Sorin Schwimmer |
last post by:
I am thinking on something in the following form:
<code>
import time
import thread
delay=True
def fn()
global delay
|
by: monomaniac21 |
last post by:
hi all
i have a script that retrieves rows from a single table, rows are
related to eachother and are retrieved by doing a series of while loops
within while loops. bcos each row contains a text field they are fairly
large. the net result is that when 60 or so results are reitreved the
page size is 400kb! which takes too long to load. is there a way of
shorterning this? freeing up the memory say, bcos what is actually
displayed is not...
|
by: Alex |
last post by:
Hi
I just want to clear something up in my head with while loops and
exceptions. I'm sure this will probably be a no brainer for most.
Check this simple pseudo-code out (vb.net):
------------------------------
try
|
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, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
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,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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();...
| |
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
|
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...
| |