I am trying to extract the user entered form data which is stored in a .txt file to a .php page using php ... how do i get the tabular display of that data ?
Thanks for the response ........ Saving to the .txt file the user entered form data using php: <?php $fp = fopen("formda.txt" ,"a"); $savestring = $Fname . "||" .$Mname . "||" .$Lname . "||" .$addr . "||" .$cit. "||" .$stat . "||" .$zip. "||" .$home. "||" .$cell. "||" .$em."||".$gender."||".$dob_month."||".$dob_day."||".$dob_year."||".$mcond."||".$Experience. "||" .$category ."\n" ; fwrite($fp,$savestring); fclose($fp); ?> Extracting out ..using php: <?php foreach (glob("formda.txt") as $filename) { $file = $filename; $contents = file($file); $string = implode($contents); $str1=explode("||",$string); foreach ($str1 as $str2) { echo nl2br(" $str2 "); } ?> output displayed is : lkmk lmkl mkl mk mlm klm lkm lkm lmlk mkl female January 9 2004 ljnbjknjlnln Expert Teen Now how do i get the above display in a tabular format with the headings as Fname ,Mname etc ..(total of 14 headings) .. what changes do i need to make in my code for the tabular display...Do let me know..
A CSS Div or an HTML Table would do the trick. Type HTML Table generator in on google to make a bunch of columns.
Simple create a table before starting the php code. After that give for loop and echo the values in the corresponding cells.. got it?...
<?php $cont=file_get_contents("formda.txt"); $data=explode("||",$cont); ?> <table> <tr><td>First name:</td><td><?php echo $data[0]; ?></td></tr> <tr><td>Middle name:</td><td><?php echo $data[1]; ?></td></tr> <?php //and so on... ?> </table> Code (markup): I think everything is very clear here... Enjoy
Thanks for the response .. I have tried in the above mentioned way and it was working .. I have a total of 17 cols to display .. But in the display of the last column data .. ( ie. My last column is Category : Teen ( data of the Category column) .. In the display it is showing up as : Category :Teen lucy ..where Lucy is the data of the first column of the next row .. So now what should i do to have my proper display as : Category :Teen ... 2) As we do not have count on the number of users entering the data in the form .. So can we use echo $data instead of explicitly giving echo $data[0] and so on .. ? i.e. can we embed echo $data in a for loop and what should the condition be ? (as we would not know in advance the number of records) .. do let me know ........
The code metioned above is working for 1 record display ..But how to work on if i have 'n'number of records .. i.e. if i give echo $data[0] .....( it extracts the first column data of the first record ) .But how do i access the data of the second record and so on.. should a for loop be used ? If so where to be used ?
I suggest you to display one entry in one row, not in one column. Just less complicated code. Firstly, using loop read file line-by-line, you can use fgets to do it. And then exploded the line you just read. Yeah I could write all the code, but it will be more useful for you to write by yourself. Also, I highly recommend you to learn MySQL. It makes storing data a lot easier.
yeah ..i tried it in the other way ..and i am able to get the display ...Thanks ..for the response ..