sort by date

I am using flat file database and i want to sort by date

i have in the text database username||date||title||message

how can i get it to sort by date?
this is for a news script im working on and i want it to appear the newest news first.

The only way I can see to do this is to fill in arrays and then sort it by date field.
Here is code example for your file format:


<?php $rows = file('data.txt'); $arr_username = array(); $arr_date = array(); $arr_title = array(); $arr_message = array(); $i = 0; if(is_array($rows)) foreach($rows as $row) { $arr = explode('||',$row); $arr_username[$i] = $arr[0]; $arr_date[$i] = strtotime($arr[1]); $arr_title[$i] = $arr[2]; $arr_message[$i] = $arr[3]; $i++; } array_multisort($arr_date,SORT_DESC,$arr_username,$arr_title,$arr_message); // and here is output, to test foreach($arr_date as $date=>$i){ echo date("m/d/Y",$date).' - '.$arr_username[$i].' - '.$arr_title[$i].' - '.$arr_message.'
'; } ?>


thank you that helped

Sponsor our Newsletter | Privacy Policy | Terms of Service