+ Post New Thread
Page 1 of 2 12 LastLast
Results 1 to 15 of 19
Web Development Thread, Filling a table with details from a file? in Coding and Web Development; Hi Everyone, I'm using dreamweaver CS5, i have a form and in that form is a table of 2 columns ...
  1. #1
    mrbios's Avatar
    Join Date
    Jun 2007
    Location
    Stroud, Gloucestershire
    Posts
    2,420
    Thank Post
    343
    Thanked 250 Times in 206 Posts
    Rep Power
    97

    Filling a table with details from a file?

    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?
    Code:
    <?php 
    
    $file = file("data.txt"); 
    
    print "<table> 
    <tr><td>Field 1</td><td>Field 2</td><td>Field 3</td></tr>"; 
    
    foreach($file as $line){ 
    $line = trim($line); 
    $split = split("\t",$line); 
    print "<tr><td>$split[0]</td><td>$split[1]</td><td>$split[2]</td></tr>"; 
    } 
    
    print "</table>"; 
    
    ?>
    Last edited by mrbios; 21st September 2010 at 11:35 AM.

  2. #2

    CESIL's Avatar
    Join Date
    Nov 2006
    Location
    Hampshire
    Posts
    1,403
    Thank Post
    109
    Thanked 267 Times in 198 Posts
    Rep Power
    168
    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??

  3. #3
    mrbios's Avatar
    Join Date
    Jun 2007
    Location
    Stroud, Gloucestershire
    Posts
    2,420
    Thank Post
    343
    Thanked 250 Times in 206 Posts
    Rep Power
    97
    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
    Last edited by mrbios; 21st September 2010 at 11:56 AM.

  4. #4

    CESIL's Avatar
    Join Date
    Nov 2006
    Location
    Hampshire
    Posts
    1,403
    Thank Post
    109
    Thanked 267 Times in 198 Posts
    Rep Power
    168
    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?

  5. Thanks to CESIL from:

    mrbios (21st September 2010)

  6. #5
    mrbios's Avatar
    Join Date
    Jun 2007
    Location
    Stroud, Gloucestershire
    Posts
    2,420
    Thank Post
    343
    Thanked 250 Times in 206 Posts
    Rep Power
    97
    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

  7. #6

    LosOjos's Avatar
    Join Date
    Dec 2009
    Location
    West Midlands
    Posts
    5,432
    Thank Post
    1,432
    Thanked 1,160 Times in 794 Posts
    Rep Power
    705
    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

  8. #7
    mrbios's Avatar
    Join Date
    Jun 2007
    Location
    Stroud, Gloucestershire
    Posts
    2,420
    Thank Post
    343
    Thanked 250 Times in 206 Posts
    Rep Power
    97
    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

  9. #8

    CESIL's Avatar
    Join Date
    Nov 2006
    Location
    Hampshire
    Posts
    1,403
    Thank Post
    109
    Thanked 267 Times in 198 Posts
    Rep Power
    168
    Try the attached...

    You should be able to use the POSTed data to build your email...
    Attached Files Attached Files

  10. Thanks to CESIL from:

    mrbios (22nd September 2010)

  11. #9
    mrbios's Avatar
    Join Date
    Jun 2007
    Location
    Stroud, Gloucestershire
    Posts
    2,420
    Thank Post
    343
    Thanked 250 Times in 206 Posts
    Rep Power
    97
    Thanks CESIL i'll give that a go

  12. #10
    mrbios's Avatar
    Join Date
    Jun 2007
    Location
    Stroud, Gloucestershire
    Posts
    2,420
    Thank Post
    343
    Thanked 250 Times in 206 Posts
    Rep Power
    97
    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>
    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 = 'mothj@archwayschool.net';
    		$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>&nbsp;</p>
    		</body>
    	</html>
    ';
    
    		mail($emailTo, $subject, $message, $headers);
    
    		$emailSent = true;
    	}
    ?>
    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
    Last edited by mrbios; 24th September 2010 at 10:04 AM.

  13. #11

    CESIL's Avatar
    Join Date
    Nov 2006
    Location
    Hampshire
    Posts
    1,403
    Thank Post
    109
    Thanked 267 Times in 198 Posts
    Rep Power
    168
    Code:
    for($i=0;$i<xx;$i++){
    	echo "<tr><td>" . $_POST['name'.$i] . "</td><td>" . $_POST['score'.$i] . "</td></tr>\n";
    }
    where xx is the number of rows+1

    to calculate the number of rows use (count($_POST)-1)/3
    Last edited by CESIL; 24th September 2010 at 09:38 PM.

  14. Thanks to CESIL from:

    mrbios (27th September 2010)

  15. #12
    mrbios's Avatar
    Join Date
    Jun 2007
    Location
    Stroud, Gloucestershire
    Posts
    2,420
    Thank Post
    343
    Thanked 250 Times in 206 Posts
    Rep Power
    97
    Thanks CESIL, though i've no idea where im putting that or what it does

  16. #13

    CESIL's Avatar
    Join Date
    Nov 2006
    Location
    Hampshire
    Posts
    1,403
    Thank Post
    109
    Thanked 267 Times in 198 Posts
    Rep Power
    168
    Does this help

    Code:
    <?php
    if(isset($_POST['submit'])) {
    		$name = trim($_POST['Student']);		
    		$emailTo = 'mothj@archwayschool.net';
    		$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>
    		<table>'
    
    //++++++++++++++++++++++++++++++
    
    for($i=0;$i<xx;$i++){
    	$message .= "<tr><td>" . $_POST['name'.$i] . "</td><td>" . $_POST['score'.$i] . "</td></tr>\n";
    }
    
    
    //++++++++++++++++++++++++++++++
    
    		$message .= '</table>
    		</body>
    	</html>';
    
    		mail($emailTo, $subject, $message, $headers);
    
    		$emailSent = true;
    	}
    ?>

  17. Thanks to CESIL from:

    mrbios (27th September 2010)

  18. #14
    mrbios's Avatar
    Join Date
    Jun 2007
    Location
    Stroud, Gloucestershire
    Posts
    2,420
    Thank Post
    343
    Thanked 250 Times in 206 Posts
    Rep Power
    97
    that helps a lot

    EDIT: syntax error on the "for($i=0;$i<xx;$i++){" line, did you intend on me changing that to: for($i=0;$i<(count($_POST)-1)/3;$i++){ as that doesn't appear to work either, im probably just doing something silly wrong
    Last edited by mrbios; 27th September 2010 at 12:42 PM.

  19. #15

    CESIL's Avatar
    Join Date
    Nov 2006
    Location
    Hampshire
    Posts
    1,403
    Thank Post
    109
    Thanked 267 Times in 198 Posts
    Rep Power
    168
    I missed a ";" after <table>'...

    oops...

  20. Thanks to CESIL from:

    mrbios (30th September 2010)

SHARE:
+ Post New Thread
Page 1 of 2 12 LastLast

Similar Threads

  1. Table Details for Serco Facility Admin
    By mattmarson in forum MIS Systems
    Replies: 23
    Last Post: 5th October 2010, 11:09 AM
  2. Nod32 filling up Hard Drive?
    By Disease in forum Windows
    Replies: 3
    Last Post: 26th May 2010, 07:14 AM
  3. MS Access - Create table linked to a Record in another table
    By RabbieBurns in forum Office Software
    Replies: 2
    Last Post: 5th May 2010, 08:52 AM
  4. Master file table corrupt!
    By GoldenWonder in forum Windows Vista
    Replies: 6
    Last Post: 19th April 2010, 01:17 PM
  5. Ghost 7.5 hangs at "dumping mft table file"
    By sakwoya in forum O/S Deployment
    Replies: 7
    Last Post: 26th November 2009, 11:06 PM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •