CalebVenner Posted June 18, 2009 Share Posted June 18, 2009 <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. Quote Link to comment https://forums.phpfreaks.com/topic/162727-inputing-into-text-box-within-php-loop/ Share on other sites More sharing options...
Adam Posted June 18, 2009 Share Posted June 18, 2009 I've not tried to understand what your code is doing, but, to insert a variable into an input: <input type="text" name="..." value="<?php echo $parts[0]; ?>" /> Quote Link to comment https://forums.phpfreaks.com/topic/162727-inputing-into-text-box-within-php-loop/#findComment-858747 Share on other sites More sharing options...
CalebVenner Posted June 18, 2009 Author Share Posted June 18, 2009 So I can run that WITHIN the PHP loop? Edit: It reads and outputs the data within the filles Order1.txt Order2.txt Order3.txt Order4.txt Order5.txt Order6.txt Order7.txt Which vary in number. Quote Link to comment https://forums.phpfreaks.com/topic/162727-inputing-into-text-box-within-php-loop/#findComment-858751 Share on other sites More sharing options...
Adam Posted June 18, 2009 Share Posted June 18, 2009 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... Quote Link to comment https://forums.phpfreaks.com/topic/162727-inputing-into-text-box-within-php-loop/#findComment-858758 Share on other sites More sharing options...
CalebVenner Posted June 18, 2009 Author Share Posted June 18, 2009 Ok, thanks, I will see if it works and report back Appreciate the help. Quote Link to comment https://forums.phpfreaks.com/topic/162727-inputing-into-text-box-within-php-loop/#findComment-858759 Share on other sites More sharing options...
CalebVenner Posted June 18, 2009 Author Share Posted June 18, 2009 Accidental double post. Quote Link to comment https://forums.phpfreaks.com/topic/162727-inputing-into-text-box-within-php-loop/#findComment-858765 Share on other sites More sharing options...
CalebVenner Posted June 18, 2009 Author Share Posted June 18, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/162727-inputing-into-text-box-within-php-loop/#findComment-858766 Share on other sites More sharing options...
Adam Posted June 18, 2009 Share Posted June 18, 2009 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>'; Quote Link to comment https://forums.phpfreaks.com/topic/162727-inputing-into-text-box-within-php-loop/#findComment-858775 Share on other sites More sharing options...
CalebVenner Posted June 18, 2009 Author Share Posted June 18, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/162727-inputing-into-text-box-within-php-loop/#findComment-858777 Share on other sites More sharing options...
Adam Posted June 18, 2009 Share Posted June 18, 2009 Add this just after your first opening PHP tag: ini_set('display_errors','1'); error_reporting(E_ALL); Quote Link to comment https://forums.phpfreaks.com/topic/162727-inputing-into-text-box-within-php-loop/#findComment-858779 Share on other sites More sharing options...
CalebVenner Posted June 18, 2009 Author Share Posted June 18, 2009 PROGRESS! I am just playing around with it a bit to save you some hassel and learn a little bit ^.^ Will post back soon, thanks so much, really really appreciate it. Quote Link to comment https://forums.phpfreaks.com/topic/162727-inputing-into-text-box-within-php-loop/#findComment-858784 Share on other sites More sharing options...
CalebVenner Posted June 18, 2009 Author Share Posted June 18, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/162727-inputing-into-text-box-within-php-loop/#findComment-858792 Share on other sites More sharing options...
Adam Posted June 18, 2009 Share Posted June 18, 2009 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 = ...... Quote Link to comment https://forums.phpfreaks.com/topic/162727-inputing-into-text-box-within-php-loop/#findComment-858796 Share on other sites More sharing options...
CalebVenner Posted June 18, 2009 Author Share Posted June 18, 2009 "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?) Quote Link to comment https://forums.phpfreaks.com/topic/162727-inputing-into-text-box-within-php-loop/#findComment-858798 Share on other sites More sharing options...
CalebVenner Posted June 18, 2009 Author Share Posted June 18, 2009 "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 Quote Link to comment https://forums.phpfreaks.com/topic/162727-inputing-into-text-box-within-php-loop/#findComment-858815 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.