Log in

View Full Version : forms and dat file formatting



big-dog1965
05-18-2009, 05:09 AM
Could someone tell me how or where to find a form excample that stores the data to a dat file then formats the data in the dat file to display on a web page.

I made a html form that stores the data to a dat file, but when I make it display on the webpage is shows every thing in the dat file. for excample
Venue|Address|Date|Time|Date2|Time2
My House|123 some street|2009-05-21|12:00pm|2009-05-22|1:00PM
The venue|... line is fields from the form
My House|..... is the data I want to display, but without the | and more like

My House
123 some street
2009-05-21 at 12:00pm
2009-05-22 at 1:00PM

I dont what to use a real sql database, and I would like it to be php or html and php. done a google and found a tut, but come to find out I would have to host with them in order for their tut to work because it uses their cgi-bin .mail2 file.

forum_amnesiac
05-26-2009, 09:15 AM
You need to extract each line of the dat file and then you can use the explode function.

In the loop for each line you can do this, eg line is called $string:


$string2 = explode('|', $string);

If you know definitely how many elements are in the array $string2, eg 3, you then do this.


echo $string2[0]." ".$string2[1]." ".$string2[2];

Otherwise you can use the PHP function count to determine how many elements, eg


$x=count($string2);
$i=0;

while ($i<$x){
echo $string2[$i]." ";
$i++;
}

Hope this helps

while

forum_amnesiac
05-26-2009, 10:35 AM
Here is a routine that reads from a .dat file and outputs the contents to the screen.


$datfile = fopen("myfile.dat", "r");
while (($data = fgetcsv($datfile, 1000, ",")) !== FALSE) {
$num = count($data);
for ($c=0; $c < $num; $c++) {
$string2 = explode('|', $data[$c]);
$x=count($string2);
$i=0;

while ($i<$x){
echo $string2[$i]." ";
$i++;
}
echo "<br />\n";
}
}
fclose($datfile);

Using the contents of the array $string2, it would be easy to better format this using HTML in your PHP.