ztealmax Posted December 17, 2006 Share Posted December 17, 2006 How do it make this so it only gets the latest file (Last modified file) in the list not all files[code]<?php $this = $PHP_SELF; $dir = $DOCUMENT_ROOT."news/"; $files = opendir($dir); $file_list = array(); $file_sort = array(); if(empty($sort))$sort="date"; if(empty($r)) $r=1; $cnt = 1; while ($file = readdir($files)) { $full_path = $dir."/".$file; if(!is_dir($full_path)) { $ext = explode(".",$file); $i=count($ext); if($i>1)$file_details["ext"] = strtolower($ext[$i-1]); $file_details["name"] = $ext[0]; $file_details["date"] = filectime($full_path); $file_list[$cnt] = $file_details; $key = strtolower($file_details[$sort]); $file_sort[$cnt] = $key; $cnt++; } } if($r)arsort($file_sort); else asort($file_sort); ?><?PHP require_once("theme.php");?><table width="465" border="0" cellpadding="3" cellspacing="0" class="smallblacktext"> <tr> <td width="174"><?php print($this);?><?php print(!$r);?>Name</td> <td width="141"><?php print($this);?><?php print(!$r);?>Date</td> </tr> <tr bgcolor="#0033CC"> <td height="3" colspan="5"> </td> </tr><?php while(list($key, $value)=each($file_sort)){ $value = $file_list[$key];?> <tr> <td width="174"><a href="read.php?text=news/<?php print($value["name"]);?>" target="content"><?php print($value["name"]);?></a></td> <td width="141"><?php print(date("Y/m/d H:i",$value["date"]));?></td> </tr><?php}?></table>[/code]Basicly what i want the script to do is to only open latest file for read.Thanx all for you help :)//Martin Link to comment https://forums.phpfreaks.com/topic/30951-how-do-it-make-this-so-it-only-gets-the-latest-file-in-the-list-not-all-files/ Share on other sites More sharing options...
artacus Posted December 17, 2006 Share Posted December 17, 2006 quick way would be to exit from your while loop after the first one. Link to comment https://forums.phpfreaks.com/topic/30951-how-do-it-make-this-so-it-only-gets-the-latest-file-in-the-list-not-all-files/#findComment-142824 Share on other sites More sharing options...
ztealmax Posted December 17, 2006 Author Share Posted December 17, 2006 [quote author=artacus link=topic=118949.msg486535#msg486535 date=1166342989]quick way would be to exit from your while loop after the first one.[/quote]can you give me a example? ;) Link to comment https://forums.phpfreaks.com/topic/30951-how-do-it-make-this-so-it-only-gets-the-latest-file-in-the-list-not-all-files/#findComment-142826 Share on other sites More sharing options...
artacus Posted December 17, 2006 Share Posted December 17, 2006 Sure, after you try to do a couple examples yourself. Link to comment https://forums.phpfreaks.com/topic/30951-how-do-it-make-this-so-it-only-gets-the-latest-file-in-the-list-not-all-files/#findComment-142831 Share on other sites More sharing options...
ztealmax Posted December 17, 2006 Author Share Posted December 17, 2006 [quote author=artacus link=topic=118949.msg486542#msg486542 date=1166343953]Sure, after you try to do a couple examples yourself.[/quote]well i did, didnt work did it , thats why i ask here..... Link to comment https://forums.phpfreaks.com/topic/30951-how-do-it-make-this-so-it-only-gets-the-latest-file-in-the-list-not-all-files/#findComment-142842 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.