Results 1 to 3 of 3

Thread: forms and dat file formatting

  1. #1
    Join Date
    Sep 2007
    Posts
    83
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default forms and dat file formatting

    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.

  2. #2
    Join Date
    Apr 2009
    Location
    Cognac, France
    Posts
    400
    Thanks
    2
    Thanked 57 Times in 57 Posts

    Default

    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:

    PHP Code:
    $string2 explode('|'$string); 
    If you know definitely how many elements are in the array $string2, eg 3, you then do this.

    PHP Code:
    echo $string2[0]." ".$string2[1]." ".$string2[2]; 
    Otherwise you can use the PHP function count to determine how many elements, eg

    PHP Code:
    $x=count($string2);
    $i=0;

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

    Hope this helps

    while

  3. #3
    Join Date
    Apr 2009
    Location
    Cognac, France
    Posts
    400
    Thanks
    2
    Thanked 57 Times in 57 Posts

    Default

    Here is a routine that reads from a .dat file and outputs the contents to the screen.

    PHP Code:
    $datfile fopen("myfile.dat""r");
    while ((
    $data fgetcsv($datfile1000",")) !== 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.

Bookmarks

Posting Permissions

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