Working with Flat File DB..

Discussion in 'PHP' started by adamjblakey, Apr 17, 2007.

  1. #1
    Hi,

    I am using a flatfile in a project i am working with but just have a little question which hopefully someone can help with.

    This is my code to display the items:

    		  
    		  <?
    			$Lines = file("database.db");
    			
    			foreach($Lines as $Key => $Val) 
    			{
    			   //explode that data into a new array:  
    			   $Data[$Key] = explode("||", $Val);
    			}
    			
    			for($K = 0; $K < sizeof($Lines); $K++) 
    			{  
    			   echo "".$Data[$K][1]."<br>";
    			   echo "".$Data[$K][2]."<br>";
    			}
    ?>
    Code (markup):
    Which is fine and works but i want this to display last entry first.

    Also it is outputting the entry like so: Entry 1|Entry 2 what i want it to do it in place of the | use a BR tag to make entry 2 below entry 1 without the |

    Cheers,
    Adam
     
    adamjblakey, Apr 17, 2007 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    This will reverse the line order:
    
    $Lines = array_reverse(file("database.db"));
    
    PHP:
    As for the other change, try this:
    
    echo '<table>';
    
    for($K = 0; $K < sizeof($Lines); $K++) 
    {  
         echo "<tr>\n";
         echo '<td>' . $Data[$K][1] . '</td>';
         echo '<td>' . $Data[$K][2] . '</td>';
         echo "</tr>\n";
    }
    
    echo "</table>\n";
    
    
    PHP:
    Untested, but give it a try.
    EDIT:

    I did just read your post again, and I'm not sure if I understood your second question right...
     
    nico_swd, Apr 17, 2007 IP
  3. adamjblakey

    adamjblakey Active Member

    Messages:
    1,121
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    80
    #3
    Hi,

    Thanks that worked fine. What i was refering to was when the array is echo'd it dispays the information like e.g. title|description.

    When it what i want it to do is title<br>description

    Cheers,
    Adam
     
    adamjblakey, Apr 17, 2007 IP