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
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...

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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>';

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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 = ......

Link to comment
Share on other sites

"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?)

Link to comment
Share on other sites

"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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.