Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
how to count the number of files to make a list?
Old 01-15-2011, 10:28 AM how to count the number of files to make a list?
Novice Talker

Posts: 6
Trades: 0
I have a directory with files like such:

1-0.html
1-1.html
1-2.html
1-3.html
2-0.html
2-1.html
3-0.html
4-0.html
4-1.html

i want to make a page that will generate links to those. for example if a person is reading file 1-0.html, the links will display all the links for 1-0 to 1-3, but not show the other links.

currently I'm doing it by hand, but since I'm learning php, i thought there would be a way to do it with variables. :-)

is there a way to do that? or is there a better way for naming hierarchy to achieve a more or less automated result? if automated, is there also a way to change the css class of the current page? like the active page will be a gray color and non active link whereas the other links will be the regular link color?



Thanks.


update:

I found this: http://www.liamdelahunty.com/tips/ph..._directory.php it shows how to list files in a directory, but it seems to list everything in a directory. how can i do something similar but just to list certain files?

Thanks again.

Last edited by ShadowHawk; 01-15-2011 at 10:44 AM.. Reason: updated.
ShadowHawk is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 01-15-2011, 02:25 PM Re: how to count the number of files to make a list?
jim1228's Avatar
Extreme Talker

Posts: 195
Name: Jim
Location: Ohio
Trades: 0
In the for loop show 3 at a time and set the counter to let you know what is the next starting page

Should work
jim1228 is offline
Reply With Quote
View Public Profile Visit jim1228's homepage!
 
Old 01-15-2011, 04:26 PM Re: how to count the number of files to make a list?
Super Spam Talker

Posts: 879
Name: Paul W
Trades: 0
readdir will only return all contents. You have to then check all names (and type if dir could contain non-html or sub-directories). It's easily done with string functions - look at substr and strstr, Th example you found is checking that each filename doesn't start with a dot - ie that it isn't a hidden file.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE


*** New:
Please login or register to view this content. Registration is FREE
PaulW is offline
Reply With Quote
View Public Profile
 
Old 01-15-2011, 08:19 PM Re: how to count the number of files to make a list?
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
JAMISONTUNES
Posts: 2,918
Name: Keith Marshall
Location: Connecticut
Trades: 0
I just wanted to give this a quick try:

PHP Code:
<?php
 
$current_group_id 
1;
 
$links = array();
 
if (
$dir dir('path/to/files/'))
{
  while (
$file $dir->read())
  {
    if (
preg_match('/^' $current_group_id '-(\d+)\.html$/'$file$match))
    {
      
$links[$match[1]] = array(
        
'file' => 'path/to/files/' $match[0],
        
'title' => 'Page ' $match[1],
      );
    }
  }
}
 
ksort($links);
 
foreach (
$links AS $link)
{
 
?>
  <a href="<?php echo $link['file']; ?>"><?php echo htmlentities($link['title']); ?></a>
<?php
 
}
__________________

<mgraphic /> - I don't have a solution but I admire the problem.
mgraphic is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to how to count the number of files to make a list?
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.16757 seconds with 12 queries