Jump to content

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/158543-forms-and-dat-file-formatting/
Share on other sites

I can read and right its the formatting of read data

parsing manually ???

 

Well, there's no one specific way to parse data. Just come up with a format that works for this situation. Create your own key characters for splitting individual pieces of data up, and use functions like explode() to parse to usable PHP information (arrays, variables, etc).

$file_string = file_get_contents("saved_data.dat");

$rows = explode("\n", $file_string); //if this doesn't work, try \r\n or just \r

foreach($rows as $value){
     $vars = explode("|", $value);
     
     echo "<b>".$vars[0]."</b><br>";
     echo $vars[1]."<br>";
     echo $vars[2]." at ".$vars[3]."<br>";
     echo $vars[4]." at ".$vars[4]."<br>";
}

$file_string = file_get_contents("saved_data.dat");

$rows = explode("\n", $file_string); //if this doesn't work, try \r\n or just \r

foreach($rows as $value){
     $vars = explode("|", $value);
     
     echo "<b>".$vars[0]."</b><br>";
     echo $vars[1]."<br>";
     echo $vars[2]." at ".$vars[3]."<br>";
     echo $vars[4]." at ".$vars[4]."<br>";
}

this is what if got and I tried the differant /r/n stuff

<?php

$file_string = file_get_contents("admin/data.dat");

$rows = explode("\r\n", $file_string); //if this doesn't work, try \r\n or just \r

foreach($rows as $value){
     $vars = explode("|", $value);
     
     echo "<b>".$vars[Venue]."</b><br>";
     echo $vars[Address]."<br>";
     echo $vars[Date]." at ".$vars[Time]."<br>";
     echo $vars[Date2]." at ".$vars[Time2]."<br>";
}

?>

I have one record but it displays at six times but nothing else no venue date time or anything but the at

 

at

 

at

 

at

 

at

 

at

I changed it back to your orginal and tried it I get

Venue

Address

Date at Time

Date2 at Date2

My House

123 some address

2009-05-15 at 12:00pm

2009-05-22 at 2009-05-22

 

So how do I get it to remove the

Venue

Address

Date at Time

Date2 at Date2

which is the form fields

 

I still need some help here. this code seems to do what I need, but it is displaying stuff that I dont know where its coming from

 

<?php
$file_string = file_get_contents("admin/data.dat");
$rows = explode("\r\n", $file_string); //if this doesn't work, try \r\n or just \r
unset($rows[0]);
foreach($rows as $value){
     $vars = explode("|", $value);
     echo "<b><i>Venue</i></b><br>";
     echo "<b>".$vars[0]."</b><br>";
     echo $vars[1]."<br>";
     echo $vars[2]." ".$vars[3]."<br>";
     echo $vars[4]." ".$vars[4]."<br>";
     echo "<hr>";
}
?>

 

Here is the out put on my webpage from the dat file results. in the dat file there are 2 entries but as you can see it has the extra at top and bottom as if there where entries made without data.

Venue

 

 

 

--------------------------------------------------------------------------------

Venue

My House

123 some address

2009-05-15 12:00pm

2009-05-22 2009-05-22

 

--------------------------------------------------------------------------------

Venue

My House

123 some address

2009-05-21 12:00pm

2009-05-22 2009-05-22

 

--------------------------------------------------------------------------------

Venue

 

 

 

--------------------------------------------------------------------------------

I also tried the other excample but it makes a table which I dont want. this is displayed in a div on the side of a webpage that has a width of 200px so the above looks ok as is but it just has the extra empty looking areas

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.