Jump to content

Inputing into Text box within php loop


CalebVenner

Recommended Posts

<html>
<meta http-equiv="refresh" content="5" > //auto refresh every 5 seconds
<head>
<link rel="stylesheet" type="text/css" href="style/style.css"> //link to css style sheet
<title>Order Display</title>
</head>
<body>
<?php
$FolderDate = date("d-m-y"); //declare veriable as current date
for ($FileNumber=1;$FileNumber<=1000;++$FileNumber) //will run following code 1000 times
{
  if (file_exists("orders/$FolderDate/Order$FileNumber.txt")) //will run following code if file exists
{							//otherwise will go to else statement
$data=file("orders/$FolderDate/Order$FileNumber.txt"); //declare variable
foreach ($data as $d) 			//for each character in file $data store as $d
	{
      		$parts=explode('=',$d); 		    //get the characters
      		print $parts[0].$parts[1].'<br><br>';    //$parts[0] stores location of character					//$parts[1] store character
	}
} 
else 
{		// when no more files are found exit the code and display the following message
        exit("All Active Files Displayed<br>Will Refresh Every 5 Seconds ... ");
}
}
?>
</body>
</html>

 

Example of current ouput

Patron's Name: Caleb Venner

 

Room: Cafe

 

Table Number: 1

 

Time: 07:05 pm

 

Entree: Roasted Vegetables with Serrano Ham

 

Entree Notes: No potatoe

 

Main Meal : Oyster mushsrooms in almond sauce

 

Main Meal Notes: Blah blaj

 

Desert: Marinated Mushrooms

 

Desert Notes: I love pie

 

Server: Peter

 

Date: 10:00:07 AM Thu, January 1st 1970

 

All Active Files Displayed

Will Refresh Every 5 Seconds ...

 

The problem that i am facing is that I do not know how to correctly input the variables $parts[0] and $parts[1] into a text box within the php loop.

 

Thanks in advance for any help.

Link to comment
https://forums.phpfreaks.com/topic/162727-inputing-into-text-box-within-php-loop/
Share on other sites

If you put that within the loop you'd end up with x amount of inputs, each containing $parts[0] from that iteration of the loop - however they'd all have the same name which isn't obviously correct HTML. You could use instead:

 

<input type="text" name="someName[]" value="<?php echo $parts[0]; ?>" />

 

Explain what you're trying to do better...

Ok, I have a folder full of text documents, what I would like to try and do is read the data from each file and output it into a textarea.

 

The problem is that the number of documents vary.

 

So I run the loop until it finds no more documents, then it ends and refreshes in 5 seconds.

 

Edit: I am trying to make it so that each file has its own text area

 

Why textarea if it refresh every 5 seconds, surely they wouldn't be able to edit it in time?

 

But basically similar concept, switch this line:

 

print $parts[0].$parts[1].'<br><br>';

 

To this:

 

print '<textarea name="someName[]">'.$parts[0].$parts[1].'</textarea><br><br>';

Thankyou for your help so far. ^.^

 

<html>
<meta http-equiv="refresh" content="60" > 
<head>
<link rel="stylesheet" type="text/css" href="style/style.css"> 
<title>Order Display</title>
</head>
<body>
<?php
$FolderDate = date("d-m-y"); 
for ($FileNumber=1;$FileNumber<=1000;++$FileNumber) 
{
  if (file_exists("orders/$FolderDate/Order$FileNumber.txt")) 
{							
$data=file("orders/$FolderDate/Order$FileNumber.txt"); 
foreach ($data as $d) 			
	{
      		$parts=explode('=',$d); 		   
      		print '<textarea name="someName[]">'.$parts[0].$parts[1].'</textarea><br><br>'; 

	}   					
} 
else 
{		
        exit("All Active Files Displayed<br>Will Refresh Every 60 Seconds ... ");
}
    print '<br><br>;
}
?>
</body>
</html>

 

This is what I have so far, the page still remains blank for some reason, and I have a problem at the moment where I do not get any error reports.

Ok, SO I get the following error

 

Notice: Undefined offset: 1 in C:\PHP Root\Restaurant\DisplayOrders.php on line 20

 

With the code

<html>
<meta http-equiv="refresh" content="15" > 
<head>
<link rel="stylesheet" type="text/css" href="style/style.css"> 
<title>Order Display</title>
</head>
<body>
<?php
ini_set('display_errors','1');
error_reporting(E_ALL);
$FolderDate = date("d-m-y"); 
for ($FileNumber=1;$FileNumber<=1000;++$FileNumber) 
{
  if (file_exists("orders/$FolderDate/Order$FileNumber.txt")) 
{							
$data=file("orders/$FolderDate/Order$FileNumber.txt"); 
foreach ($data as $d) 			
	{
      		$parts=explode('=',$d); 		   
      		print '<textarea name="someName[]" style="width: 256;height: 128;">'.$parts[0].$parts[1].'</textarea><br><br>'; 

	}   					
} 
else 
{		
        exit("All Active Files Displayed<br>Will Refresh Every 15 Seconds ... ");
}
}
?>
</body>
</html>

 

Line 20 Being

print '<textarea name="someName[]" style="width: 256;height: 128;">'.$parts[0].$parts[1].'</textarea><br><br>'; 

 

Also I was wondering how I insert a break after each line into the following code snippet, I had it before, have just forgotten

			

                        fputs($file, "Extra Notes: $notes");
		fputs($file, "Server: $servingstaff");
		fputs($file, "Date: $time");

 

Thanks you to anyone that helps.

 

 

EDIT: Will just use "/n" for the break

 

It's a notice telling you that $parts[1] isn't actually set (the key '1' doesn't exist). Just quickly add some debugging code to find out what's in the $data array, like so:

 

print '<pre>';print_r($data);print '</pre>';

 

Add that just after $data = ......

"Array

(

    [0] => Patron's Name: Caleb Venner

 

    [1] => Room: Cafe

 

    [2] => Table Number: 1

 

    [3] => Time: 08:43 pm

 

    [4] => Meal 1: Lemon antichokes

 

    [5] => Meal 2: Lemon antichokes

 

    [6] => Meal 3: Lemon antichokes

 

    [7] => Extra Notes: Test test est est est testing

 

    [8] => Server: Peter

 

    [9] => Date: 10:00:08 AM Thu, January 1st 1970

 

)

 

 

Notice: Undefined offset: 1 in C:\PHP Root\Restaurant\DisplayOrders.php on line 21

Patron's Name: Caleb Venner "

 

Also (I know I'm annoying ^.^), Becuase It is output to the text file with a break between each set of info. when they are input to the page they all get displayed in a spereate text box per line, if I leave out the breaks it's not very legable as the entire text file is displayed in the same box with one space between each set of information., any ideas?)

"Array

(

    .[0] => Patron's Name: Caleb Venner

 

    [1] => Room: Cafe

 

    [2] => Table Number: 1

 

    [3] => Time: 08:43 pm

 

    [4] => Meal 1: Lemon antichokes

 

    [5] => Meal 2: Lemon antichokes

 

    [6] => Meal 3: Lemon antichokes

 

    [7] => Extra Notes: Test test est est est testing

 

    [8] => Server: Peter

 

    [9] => Date: 10:00:08 AM Thu, January 1st 1970

 

)

 

 

 

Notice: Undefined offset: 1 in C:\PHP Root\Restaurant\DisplayOrders.php on line 21

Patron's Name: Caleb Venner "

 

Should be that

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.