#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Location
    Comber, Belfast, United Kingdom
    Posts
    17
    Rep Power
    0
    I've got a news system installed on my site at www.rctmadness.com and i need to make a change to the newsdisplay script so instead of showing all of the news txt files in the news directory it'll only display say the first 10 or sometihng (probobly in most recent order like it already is). Its probobly a simple change to one of the functions but im not sure of which. Here is the code:
    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>
    <?

    $newsdir = "/usr/local/customer/virtualfp/www.thesims.co.uk/rctm/news/";

    $news=opendir($newsdir);
    $files = array();
    while ($file = readdir($news)) {
    if ($file != "." && $file != ".." && $file != "news.php" && $file != "index.php") {
    $files[] = $file;
    }
    rsort($files);
    }
    for (reset ($files); list ($key, $value) = each ($files); ) {
    include($newsdir . '/' . $value);
    }
    closedir($news);
    ?>
    [/code]


    ------------------


    [This message has been edited by Ed Mack (edited October 14, 2000).]
  2. #2
  3. Banned (not really)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 1999
    Location
    Brussels, Belgium
    Posts
    14,646
    Rep Power
    4492
    Can't you just use a for loop, instead of while?
    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>
    <?
    $newsdir = "/usr/local/customer/virtualfp/www.thesims.co.uk/rctm/news/";
    $news=opendir($newsdir);
    $files = array();
    for($count=0;$count<10;$count++)
    $file = readdir($news);
    if ($file != "." && $file != ".." && $file != "news.php" && $file != "index.php") {
    $files[] = $file;
    }
    rsort($files);
    }
    for (reset ($files); list ($key, $value) = each ($files); ) {
    include($newsdir . '/' . $value);
    }
    closedir($news);
    ?>
    [/code]

    [This message has been edited by SepodatiCreations (edited October 14, 2000).]
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Location
    Comber, Belfast, United Kingdom
    Posts
    17
    Rep Power
    0
    That doesn't work

    ------------------
  6. #4
  7. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Location
    Comber, Belfast, United Kingdom
    Posts
    17
    Rep Power
    0
    Here is a breakdown of it:
    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>

    <?

    $newsdir = "/usr/local/customer/virtualfp/www.thesims.co.uk/rctm/news/";
    $news=opendir($newsdir);
    $files = array();
    while ($file = readdir($news)) {
    if ($file != "." && $file != ".." && $file != "news.php" && $file != "index.php") {
    $files[] = $file;
    }
    rsort($files);
    }
    //This line is the one that loops printing out the news items. $newsdir is the path then a slash and then value witch will be a text files name.
    so it'll give somthing like "path above/whatever.txt". Understand any more? I need to change the "for" line ot run a couple of times but dont know where. I might have to add the second input in the middle saying 3 ect.//
    for (reset ($files); list ($key, $value) = each ($files); ) {
    include($newsdir . '/' . $value);
    }
    closedir($news);
    ?>


    [/code]

    ------------------


    [This message has been edited by Ed Mack (edited October 14, 2000).]
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2000
    Location
    Newark, DE, USA
    Posts
    39
    Rep Power
    15
    Give this a whirl ... I just added a counter to your for() loop.
    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>

    <?

    $newsdir = "/usr/local/customer/virtualfp/www.thesims.co.uk/rctm/news/";
    $news=opendir($newsdir);
    $files = array();
    while ($file = readdir($news)) {
    if ($file != "." && $file != ".." && $file != "news.php" && $file != "index.php") {
    $files[] = $file;
    }
    rsort($files);
    }
    //This line is the one that loops printing out the news items. $newsdir is the path then a slash and then value witch will be a text files name.
    so it'll give somthing like "path above/whatever.txt". Understand any more? I need to change the "for" line ot run a couple of times but dont know where. I might have to add the second input in the middle saying 3 ect.//
    $fileCount = 0;
    for (reset ($files); list ($key, $value) = each ($files) && fileCount < 10; fileCount++) {
    include($newsdir . '/' . $value);
    }
    closedir($news);
    ?>


    [/code]



    ------------------
    ~Chris
  10. #6
  11. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Location
    Comber, Belfast, United Kingdom
    Posts
    17
    Rep Power
    0
    I just get
    Parse error: parse error, expecting `')'' in /usr/local/customer/virtualfp/www.thesims.co.uk/rctm/displaynews.php on line 11

    (line 11 is the one wity each and the added stuff)

    ------------------
  12. #7
  13. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Location
    Comber, Belfast, United Kingdom
    Posts
    17
    Rep Power
    0
    the output is at www.thesims.co.uk/rctm/displaynews.php

    ------------------
  14. #8
  15. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Location
    Comber, Belfast, United Kingdom
    Posts
    17
    Rep Power
    0
    i added a ; in $filecount++

    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>
    <? $newsdir = "/usr/local/customer/virtualfp/www.thesims.co.uk/rctm/news/";
    $news=opendir($newsdir);
    $files = array();
    while ($file = readdir($news)) {
    if ($file != "." && $file != ".." && $file != "news.php" && $file != "index.php") {
    $files[] = $file;
    }
    rsort($files);
    }

    for (reset ($files); list ($key, $value) = each ($files)) && $fileCount = 0; fileCount < 10; fileCount++ {
    include($newsdir . '/' . $value);
    }
    closedir($news);
    ?>
    [/code]

    [This message has been edited by Ed Mack (edited October 14, 2000).]
  16. #9
  17. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Location
    Comber, Belfast, United Kingdom
    Posts
    17
    Rep Power
    0
    iv'e changed the code again slight ly but the "for" line still gives the same error

    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>
    <? $newsdir = "/usr/local/customer/virtualfp/www.thesims.co.uk/rctm/news/";
    $news=opendir($newsdir);
    $files = array();
    while ($file = readdir($news)) {
    if ($file != "." && $file != ".." && $file != "news.php" && $file != "index.php") {
    $files[] = $file;
    }
    rsort($files);
    }
    reset ($files);

    for ($fileCount = 0; fileCount < 5; fileCount++{
    list ($key, $value) = each ($files);
    include($newsdir . '/' . $value);
    }
    closedir($news);
    ?>
    [/code]
  18. #10
  19. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2000
    Location
    Newark, DE, USA
    Posts
    39
    Rep Power
    15
    OOPS!!! I forgot the $'s on the fileCount variables within your for loop! Sorry about that

    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">quote:</font><HR>Originally posted by cwwesley:
    Give this a whirl ... I just added a counter to your for() loop.
    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>

    <?

    $newsdir = "/usr/local/customer/virtualfp/www.thesims.co.uk/rctm/news/";
    $news=opendir($newsdir);
    $files = array();
    while ($file = readdir($news)) {
    if ($file != "." && $file != ".." && $file != "news.php" && $file != "index.php") {
    $files[] = $file;
    }
    rsort($files);
    }
    //This line is the one that loops printing out the news items. $newsdir is the path then a slash and then value witch will be a text files name.
    so it'll give somthing like "path above/whatever.txt". Understand any more? I need to change the "for" line ot run a couple of times but dont know where. I might have to add the second input in the middle saying 3 ect.//
    $fileCount = 0;
    for (reset ($files); list ($key, $value) = each ($files) && $fileCount < 10; $fileCount++) {
    include($newsdir . '/' . $value);
    }
    closedir($news);
    ?>


    [/code]


    [/quote]



    ------------------
    ~Chris
  20. #11
  21. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Location
    Comber, Belfast, United Kingdom
    Posts
    17
    Rep Power
    0
    I tried that and

    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>
    <?

    $newsdir = "/usr/local/customer/virtualfp/www.thesims.co.uk/rctm/news/";
    $news=opendir($newsdir);
    $files = array();
    while ($file = readdir($news)) {
    if ($file != "." && $file != ".." && $file != "news.php" && $file != "index.php") {
    $files[] = $file;
    }
    rsort($files);
    }
    reset ($files);

    for ($fileCount = 0; $fileCount < 5; $fileCount++ {
    list ($key, $value) = each ($files);
    include($newsdir . '/' . $value);
    }
    closedir($news);
    ?>
    [/code]

    but both gave me a blank page

    ------------------
  22. #12
  23. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Location
    Comber, Belfast, United Kingdom
    Posts
    17
    Rep Power
    0
    Anyone?

    ------------------
  24. #13
  25. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Posts
    51
    Rep Power
    15
    id say, start over, use sql. Just pull em out ofthe database and loop through em. You can even make a lil script that lets you administer the whole thing in a few hours. (im doin this for a site myself)

    cya

    Sam

    ------------------
  26. #14
  27. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Location
    Comber, Belfast, United Kingdom
    Posts
    17
    Rep Power
    0
    I really want to do that but dont have sql!

    ------------------

Similar Threads

  1. Replies: 2
    Last Post: February 8th, 2004, 12:56 PM
  2. stl map find with key a class
    By sevgolds in forum C Programming
    Replies: 2
    Last Post: January 27th, 2004, 06:33 AM
  3. i need a prog for find the exp value
    By kulo in forum C Programming
    Replies: 5
    Last Post: January 23rd, 2004, 04:44 PM
  4. Replies: 0
    Last Post: January 18th, 2004, 06:17 AM
  5. stop image rotation on Mouseover?
    By santy in forum HTML Programming
    Replies: 0
    Last Post: December 21st, 2003, 10:22 PM

IMN logo majestic logo threadwatch logo seochat tools logo