mrbios Posted September 21, 2010 Posted September 21, 2010 (edited) Hi Everyone, I'm using dreamweaver CS5, i have a form and in that form is a table of 2 columns and 32 rows I want to fill the left hand column using the details from a file (in this case a list of students names) BUT with a twist.....i want it to fill the left hand column with the student names each time the page loads, for example if that particular file is changed or updated i want the names in that column to change with it. Is there any way to do this? I'd prefer a method that works in php/html, no asp etc Cheers EDIT: Found this online, no idea how it works or if it would be suitable for my needs? can someone explain what it is doing on each line and wether it would work (or be adapted to work) for my requirements? $file = file("data.txt"); print "</pre><table> Field 1Field 2Field 3"; foreach($file as $line){ $line = trim($line); $split = split("\t",$line); print "$split[0]$split[1]$split[2]"; } print "</table>"; <br><br>?> Edited September 21, 2010 by mrbios
CESIL Posted September 21, 2010 Posted September 21, 2010 This is not difficult at all... Simply read the list of names from the file when the page loads and create the table on the fly... Or am I missing something that makes this harder??
mrbios Posted September 21, 2010 Author Posted September 21, 2010 (edited) What makes it harder is that im a web coding novice so i've no idea how to do it Basically what i have is a form, this form has a 2 column table, the right column teachers are going to fill details into the left column i want to be automatically generated from a file every time the page loads The reason for this is i want one member of staff to be able to update the names in the list when students change tutor groups etc without relying on me to go into the code and have to change it that way. Once teachers have filled the right column in with details they submit it and that then gets emailed to that member of staff who will also be updating the names lists Edited September 21, 2010 by mrbios
CESIL Posted September 21, 2010 Posted September 21, 2010 The code you posted will work as long as your file is tab separated. If it uses a different separator then change the "\t" to whatever you use ("," for CSV for example) The harder part is what happens when the form is submitted...should the data file be updated? 1
mrbios Posted September 21, 2010 Author Posted September 21, 2010 Ok that's working, cheers, i've got two more problems now though, the first of which is that the table is created by php which is lovely and wonderful except now i don't know how to make the second column text boxes for the user to enter data into which will eventually be submitted by the forms submit button. My second problem is that previously i was generating the email using the variables of the text box names etc but now that they are also gone thanks to this lovely bit of php i no longer know how to take the information generated by the php as well as the information i want from problem one and put that into an email
LosOjos Posted September 21, 2010 Posted September 21, 2010 I'll admit straight away I've skim read this thread so far so excuse me if I'm missing the point, but wouldn't it be easier to use XML and a transform file? If your list of student names is being generated from SIMS/CMIS it won't be difficult to make it output XML rather than CSV, then the page will read the XML file each time and populate the table accordingly. Have a look at W3Schools if you're unsure about XSLT: XSLT Tutorial
mrbios Posted September 21, 2010 Author Posted September 21, 2010 I'd do it whatever way is simplest, im not bothered in how i implement it so long as i can do it with minimal knowledge required on how to implement it My final goal is as i say a column in which i can get a staff member to update without ever needing to access the server or go through any code Second column with text boxes that teachers can type into a submit button to submit the information contained in both columns once the information has been entered via email That's all i need, don't really care how i do it, at the moment my sites are all standard html or php so it's easiest for me if they are kept as such
CESIL Posted September 22, 2010 Posted September 22, 2010 Try the attached... You should be able to use the POSTed data to build your email...data.zip 1
mrbios Posted September 24, 2010 Author Posted September 24, 2010 (edited) That seems to have worked perfectly CESIL, only bit i need help with now is how do i make the second column of the table editable? is there a bit of code i can put into that PHP to make them writable? EDIT: actually i have a slightly different problem now, this is the code i have for the page: [CODE]</head> <body> <h1 align="center"><u>7B Praise Points</u></h1> <div id="contact-wrapper"> <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" id="contactform"> <?php $file = file("7B.txt"); $count = 0; print "<table cellspacing='2'>\n <tr><td>Student Name</td><td>Number of Praise Points</td></tr>\n"; foreach($file as $line){ $line = trim($line); $split = split("\t",$line); print "<tr>\n<td>$split[0]<input name='name$count' type='hidden' value='$split[0]'></td>\n<td>$split[1]<input name='points$count' type='hidden' value='$split[1]'></td>\n</tr>"; $count++; } print "</table>"; ?> <p> <input name="submit" type="submit" value="Submit"> </p> </form> </div> </body> </html>[/CODE] That's the bit that generates the page, so i need something in there so that the second column can be edited and then submitted along with the email This is then the code i've got for the email which is held within the same page at the top (as you can see i changed your form line at the top) [CODE] <?php if(isset($_POST['submit'])) { $name = trim($_POST['Student']); $emailTo = '[email protected]'; $subject="7B Praise Points"; $headers = "From: " . $emailTo . "\r\nReply-To: " . $emailTo; $headers .= 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; $message = ' <html> <head> <title>7B Praise Points</title> </head> <body> <h1 align="center"><strong>7B Praise Points</strong></h1> <pre> </pre> <p> </p> </body> </html> '; mail($emailTo, $subject, $message, $headers); $emailSent = true; } ?> [/CODE] So i also need something in the email section to take the information from the first set of PHP to formulate it in the email the same as it is displayed on the page as well as the information which i want to have been inputted into the text boxes Between the two bits of code is a load of css code which isn't important Edited September 24, 2010 by mrbios
CESIL Posted September 24, 2010 Posted September 24, 2010 (edited) for($i=0;$i echo "" . $_POST['name'.$i] . "" . $_POST['score'.$i] . "\n"; } where xx is the number of rows+1 to calculate the number of rows use (count($_POST)-1)/3 Edited September 24, 2010 by CESIL 1
mrbios Posted September 27, 2010 Author Posted September 27, 2010 Thanks CESIL, though i've no idea where im putting that or what it does
CESIL Posted September 27, 2010 Posted September 27, 2010 Does this help if(isset($_POST['submit'])) { $name = trim($_POST['Student']); $emailTo = '[email protected]'; $subject="7B Praise Points"; $headers = "From: " . $emailTo . "\r\nReply-To: " . $emailTo; $headers .= 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; $message = ' 7B Praise Points 7B Praise Points </pre><table>' //++++++++++++++++++++++++++++++ for($i=0;$i $message .= "" . $_POST['name'.$i] . "" . $_POST['score'.$i] . "\n"; } //++++++++++++++++++++++++++++++ $message .= '</table><br> <br>';<br><br> mail($emailTo, $subject, $message, $headers);<br><br> $emailSent = true;<br>}<br>?&g 1
mrbios Posted September 27, 2010 Author Posted September 27, 2010 (edited) that helps a lot EDIT: syntax error on the "for($i=0;$i Edited September 27, 2010 by mrbios
mrbios Posted September 30, 2010 Author Posted September 30, 2010 Hi CESIL, yea putting the ";" in worked a treat, been a bit busy on other things the past few days so hadn't had a chance to test it, it now submits an email with all the names and a blank second column of data, so all i need now is the ability to make the second column into a column staff can enter data in to, once i've done that im pretty much done, i think it's the last thing i need any help with anyway So nearly there now that i can taste victory!
CESIL Posted September 30, 2010 Posted September 30, 2010 You need to change: foreach($file as $line){ $line = trim($line); $split = split("\t",$line); print "\n$split[0]\n$split[1]\n"; $count++; } to foreach($file as $line){ $line = trim($line); $split = split("\t",$line); print "\n$split[0]\n\n"; $count++; } 1
mrbios Posted September 30, 2010 Author Posted September 30, 2010 Excellent, thank you very much CESIL, you've been a grand help
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now