big-dog1965 Posted May 18, 2009 Share Posted May 18, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/158543-forms-and-dat-file-formatting/ Share on other sites More sharing options...
Masna Posted May 18, 2009 Share Posted May 18, 2009 Look into file_put_contents() and file_get_contents(). You can use the first to write to a .dat file and the second to read from it (passing and getting strings, respectively). You'll have to do the parsing manually. Quote Link to comment https://forums.phpfreaks.com/topic/158543-forms-and-dat-file-formatting/#findComment-836197 Share on other sites More sharing options...
big-dog1965 Posted May 18, 2009 Author Share Posted May 18, 2009 I can read and right its the formatting of read data parsing manually ??? Quote Link to comment https://forums.phpfreaks.com/topic/158543-forms-and-dat-file-formatting/#findComment-836199 Share on other sites More sharing options...
Masna Posted May 18, 2009 Share Posted May 18, 2009 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). Quote Link to comment https://forums.phpfreaks.com/topic/158543-forms-and-dat-file-formatting/#findComment-836201 Share on other sites More sharing options...
big-dog1965 Posted May 18, 2009 Author Share Posted May 18, 2009 I dont really understand how to do that stuff Quote Link to comment https://forums.phpfreaks.com/topic/158543-forms-and-dat-file-formatting/#findComment-836203 Share on other sites More sharing options...
Masna Posted May 18, 2009 Share Posted May 18, 2009 $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>"; } Quote Link to comment https://forums.phpfreaks.com/topic/158543-forms-and-dat-file-formatting/#findComment-836207 Share on other sites More sharing options...
big-dog1965 Posted May 18, 2009 Author Share Posted May 18, 2009 $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 Quote Link to comment https://forums.phpfreaks.com/topic/158543-forms-and-dat-file-formatting/#findComment-836222 Share on other sites More sharing options...
big-dog1965 Posted May 18, 2009 Author Share Posted May 18, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/158543-forms-and-dat-file-formatting/#findComment-836240 Share on other sites More sharing options...
Daniel0 Posted May 18, 2009 Share Posted May 18, 2009 Add unset($rows[0]); before the foreach. Also, please read the part of the manual that covers syntax. $vars[Venue] etc. is not the correct way to access array indices. Quote Link to comment https://forums.phpfreaks.com/topic/158543-forms-and-dat-file-formatting/#findComment-836249 Share on other sites More sharing options...
big-dog1965 Posted May 18, 2009 Author Share Posted May 18, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/158543-forms-and-dat-file-formatting/#findComment-836617 Share on other sites More sharing options...
Masna Posted May 18, 2009 Share Posted May 18, 2009 unset($rows[1]); unset($rows[count($rows)-1]); Quote Link to comment https://forums.phpfreaks.com/topic/158543-forms-and-dat-file-formatting/#findComment-836635 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.