PowWeb Forums - The Perfect Community for the Perfect Host  

Register now to interact with over 11,000 members! Registered users have Posting Privileges, free access to Private Messaging, Email Notifications and more.

Go Back   PowWeb Community Forums > The PowWeb Platform > PHP
User Name
Password
Register FAQ Members List Search Today's Posts Mark Forums Read

Closed Thread
 
Thread Tools
Old 1-21-04, 11:07 AM   #1
Storms
Guest
 
Posts: n/a
filedate and prev - next

1) I guess there is possible to extract filedate(last updated), but by which command?

2) In a script I run a foreach loop giving me a list of items. I'd like to limit the listing to the last 10, and add following functions... prev 10 | all |and next 10 ( if count($i)>count($i)-10 )

Any allready made willing to share?

regs
 
Old 1-21-04, 11:28 AM   #2
rh0926
Go Blue!
 
rh0926's Avatar
 
Join Date: May 2002
Location: OH, USA
Posts: 143
Reputation: 7
1) try the filemtime function in PHP.

PHP Code:
<?php
// outputs e.g.  somefile.txt was last modified: December 29 2002 22:16:23.

$filename 'somefile.txt';
if (
file_exists($filename)) {
   echo 
"$filename was last modified: " date ("F d Y H:i:s."filemtime($filename));
}
?>
2) Sorry, I'm still learning PHP and I'll leave it up to somebody else.
__________________
Rob
rh0926 is offline  
Old 1-21-04, 11:46 AM   #3
Pig
foo
 
Pig's Avatar
 
Join Date: Jan 2003
Location: Seattle-ish
Posts: 2,597
Reputation: 106
2) Search for pagination on phpbuilder.com/board or google. It's been beat to death too many times to repost here.
__________________
webhead.cc
Pig is offline  
Old 1-22-04, 08:04 AM   #4
Storms
Guest
 
Posts: n/a
thx rh0926!

For the pagination.... I found 1000 for MySQl but none for flatfile... I'guess this can be re-written some to work...

Bellow is modifed pagination script for MySQL...

I'd like to make this work for a flatfile... As it is it will no print out the wanted result... as it seems to be a list and definition issue:

PHP Code:
<?


$recordLimit
5;    // Limit per page

/*==============================================*/
/*==Font control for the Next/Prev Naviagation==*/
/*==============================================*/
$prevStatus "Show Previous $recordLimit Results";
$nextStatus "Show Next $recordLimit Results";
$prevLink     "< Previous|";
$nextLink     "|Next >";
$fontfamily "tahoma, helvetica";
$fontsize    "13px";
$fontcolor    "#000000";
$inactivecolor "#666666";    // Color for when there is no link
$fontweight    "700";
$textdecoration "none";



/*========================================*/
/*==Open the flat file=*/
/*========================================*/
$fp fopen('xxxx.txt','r');
   if (!
$fp)
   {
      echo 
'<p>file not found or error opening file</p>';
      exit;
   }
$i 0;
   while ( !
feof($fp) AND $i++ < 2000 )

   {
      
$num fgets($fp999);
      if( 
$i <= ) continue;  

      
$match preg_split"/[\t ]+/",$num ); // splitting the tabs and making each column readble

 
if( count($match)>) {

          
$date[] = $match[0];
          
$advice[] = $match[1]; // which column to read
          
$msg[] = $match[2]; 
          
$target[] = $match[3];// which column to read
          
$targetprice[] = $match[4];
          
$result[] = $match[5];
          

      }
 }
/*==========================================*/
/*==Window Status of individual page links==*/
/*==========================================*/
function pageStatus($i){
 echo 
" Click to View Page $i";
}
/*==================================================*/
/*==If thisOffset not set, set to zero==============*/
/*==================================================*/
if (!isset($thisOffset) || $thisOffset 0$thisOffset=0
if (
$action==search$thisOffset $thisOffset 1;

/*==================================================*/
/*==This is to count the line index of the results==*/
/*=============if not set, set to zero==============*/
/*==================================================*/
if (!isset($lineIndex) || $lineIndex 0$lineIndex=0
if (
$action==search$lineIndex $lineIndex 1;


$totalRowsNum count($date);

/*==========================================*/
/*==Append the limit and offset to the sql==*/
/*==========================================*/
$sql.=" Limit $thisOffset,$recordLimit";
### needs re-writing
/*===================================================*/
/*==Query and fetch array with the limit and offset==*/
/*===================================================*/
$query mysql_query($sql$con);
while (
$result=mysql_fetch_array($query)){
### needs re-writing
/*==========================================*/
/*====== Your results layout goes here =======*/
/*============================================*/
echo "$date[$i]<br>";
}

    
//**Example:
    //$category=$result['CATEGORY'];
    //$title=$result['TITLE'];
    //echo "$lineIndex. - $category - $title<br>";

/*===================================================================*/
/*==If the number of returned is less than the limit, show nothing===*/
/*===================================================================*/        
if ($totalRowsNum <= $recordLimit) {
// less than recordLimit returned.
} else {
  
/*==============================================*/
/*==If the current offset is not equal to zero==*/
/*==Show the link. Else (if>0) show just text===*/
/*==============================================*/
if ($thisOffset!=0) { $prevOffset intval($thisOffset-$recordLimit); 
echo 
"<a style='font-family:$fontfamily; font-size:$fontsize; color:$fontcolor; font-weight:$fontweight;"
    
." text-decoration:$textdecoration;' onmouseover=\"window.status='$prevStatus'; return true\""
    
." onmouseout=\"window.status=''\" href=\"$PHP_SELF?thisOffset=$prevOffset&lineIndex=$prevOffset\">"
    
."$prevLink</a>&nbsp;";      

else { echo 
"<span style='font-family:$fontfamily; font-size:$fontsize; color:$inactivecolor;"
           
." font-weight:$fontweight; text-decoration:$textdecoration;'>$prevLink</span>&nbsp;";
}

/*================================================================*/
/*==Divide total rows by record limit to get the number of pages==*/    
/*================================================================*/
$totalPages intval($totalRowsNum/$recordLimit); 
        
/*===========================================================*/
/*==If remainder is left from division increment totalPages==*/
/*===========================================================*/
if ($totalRowsNum%$recordLimit$totalPages++; 
    
/*===========================================================*/
/*==Using a for() loop, Display links for each page. 1 2 3==*/
/*===========================================================*/        
for ($i=1;$i<=$totalPages;$i++) { 

/*==================================================================*/
/*==If the page being viewed is the current page, disable the link==*/
/*==================================================================*/     
if ((intval($thisOffset/$recordLimit)) == (intval($i-1))) {
    
echo 
"&nbsp;<span style='font-family:$fontfamily; font-size:$fontsize; color:$inactivecolor;"
    
." font-weight:$fontweight; text-decoration:$textdecoration;'>$i</span>&nbsp;";
     
} else {     
/*=======================================================*/
/*==If not current page, set nextOffset and display link==*/
/*=======================================================*/
$nextOffsetintval($recordLimit*($i-1)); 
    
echo 
"&nbsp;<a style='font-family:$fontfamily; font-size:$fontsize; color:$fontcolor;"
    
." font-weight:$fontweight; text-decoration:$textdecoration;' onmouseover=\"window.status='";
           
pageStatus($i);
echo 
"'; return true\" onmouseout=\"window.status=''\""
    
." href=\"$PHP_SELF?thisOffset=$nextOffset&lineIndex=$nextOffset\">$i</a>&nbsp;"
}     

    
/*==========================================================================*/
/*==If the page is not the last page, set the nextOffset and show the link==*/
/*==============If the page is the last page disable the link===============*/ 
/*==========================================================================*/
if (!(intval(((intval($thisOffset/$recordLimit))+1))==$totalPages) && $totalPages!=1) {
$nextOffset intval($thisOffset+$recordLimit);
 
echo 
"&nbsp;<a style='font-family:$fontfamily; font-size:$fontsize; color:$fontcolor; font-weight:$fontweight;"
    
." text-decoration:$textdecoration;' onmouseover=\"window.status='$nextStatus'; return true\""
    
." onmouseout=\"window.status=''\" href=\"$PHP_SELF?thisOffset=$nextOffset&lineIndex=$nextOffset\">$nextLink</a><p>\n"

else echo 
"&nbsp;"
        
."<span style='font-family:$fontfamily; font-size:$fontsize; color:$inactivecolor;"
        
." font-weight:$fontweight; text-decoration:$textdecoration;'>$nextLink</span><p>";
}

//End
?>

</body>
</html>
 
Old 1-23-04, 03:54 PM   #5
Storms
Guest
 
Posts: n/a
I guess the script was to long to get the attention, so I narrow the problem down to the actual loop...

PHP Code:
$totalRowsNum count($date);

/*===================================================*/
/*==Query and fetch array with the limit and offset==*/
/*===================================================*/
$i $thisOffset;
while (
$i <= $totalRowsNum) {

/*==========================================*/
/*====== Your results layout goes here =======*/
/*============================================*/
echo "$date[$i]<br>";
$i++;

A loop like this gives the result on the expected number of pages, but lists wrong inside the pages...

e.g

Total number of data entries = 13
Limit per page is = 5

This gives the correct number of pages
<prev| 1 2 3 |next>

but
page 1 displayes 15 queries (1-13)
page 2 displayes 8 queries (6-13)
page 3 displayes 3 queries (10-13)

it is suppose to display

page 1: 1-5
page 2: 6-10
page 3: 11->
 
Old 1-23-04, 07:42 PM   #6
B&T
Just tryin' to help
 
B&T's Avatar
 
Join Date: Jan 2003
Location: along the journey
Posts: 8,036
Reputation: 125
It is doing what you asked:

while ($i <= $totalRowsNum) {

You need to ask for not <= the total number of rows, but to the next page (+5). Should be:

while ($i <= ($thisOffset + $lmitperpage)) {

note - I did not search the script for the correct variable name for limit per page, but you get the idea. It really is a little bit harder than that, because you should check to make sure you do not run over the total rows, but you can figure that out I am sure.

If $thisOffset + $lmitperpage is > total rows then use total rows.
__________________
Enhance your PowWeb experience @ B&T's Tips & Scripts
Got some free time? You can find Nothing of Value @ PrettyWorthless.com
B&T is offline  
Old 1-24-04, 01:01 PM   #7
Storms
Guest
 
Posts: n/a
thx a lot B&T !

It is allways so obvious....

Now it works as intended....

Anyone in need of a working version of pagaination for flatfiles just notify me! If you like I can mail you the complete script B&T for your script collection at your site...

regs
 
Old 1-24-04, 02:19 PM   #8
B&T
Just tryin' to help
 
B&T's Avatar
 
Join Date: Jan 2003
Location: along the journey
Posts: 8,036
Reputation: 125
Now that you have it running . . . there is a more efficient way to deal with date ordered flat files.

If you name the files with the unix date, then you can read the directory names into an array (not the data, just the file names). That is very fast and consumes little resources.

Then you sort the array of file names (the dates) how you want. Then do the processing on the array to determine what to show (your page processing). Then in processing you use the array values to read ONLY the 5 that will show on the page.

Not a big deal with 18 files, but much more efficient if you have 100's.

Would cause you to change:

1) Your file naming convention.
2) The initial read to read the directory and not files.
3) In the print a page routine you would read the files to be displayed as you need them.

This works very well for me. Is very fast. And is friendly to Powweb's servers
__________________
Enhance your PowWeb experience @ B&T's Tips & Scripts
Got some free time? You can find Nothing of Value @ PrettyWorthless.com
B&T is offline  
Closed Thread

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 03:51 PM.


Contents ©PowWeb, Inc. ~ vBulletin, Copyright © 2000-2007 Jelsoft Enterprises Limited.