SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    [Call me Bram] iBram007's Avatar
    Join Date
    Feb 2001
    Location
    Belgium
    Posts
    339
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    How can I sort this while?
    (the last 10)


    Code:
    <?
    $filename = "http://mydomain.com/url/url.txt";
    $fd = fopen( $filename, "r" );
    
    while (!feof( $fd)){
    $content = fgets( $fd, 10000);
    $ex = explode("||",$content);
    $url = $ex[1];
    $description = $ex[2];
    $date = $ex[0];
    $i++;
    if ($i <= 10) {
        		echo"<a class=no href='$url'>$url</a> - $description<hr class=middenhcel size=1>";
    	}
    }
    fclose($fd);
    ?>

    date format: 24022001

  2. #2
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Personally I would take this route, the dates are only printed to show you that the order is correct.

    php code:
    PHP Code:
    <?
    $filename 
    "./url.txt";
    $data file($filename);

    foreach(
    $data as $content) {
        
    $ex explode("||",$content);
        
    $tmp $ex[0];
        
    $utime mktime(0,0,0,substr($tmp22), substr($tmp,0,2), substr($tmp,4,4));
        
    $links[] = array("date" => $utime,
                         
    "url" => $ex[1],
                         
    "desc" => $ex[2]
                         );
        }
    asort($links);
        
    foreach(
    $links as $key => $val) {
        if(
    $i<10) {
            
    printf('<a href="%s">%s</a> - %s - %s<hr class=middenhcel size=1>%s'$links[$key]["url"], $links[$key]["url"], $links[$key]["desc"], date("d-m-y"$links[$key]["date"]), "\n");
            }
        else {
            break;
            }
        
    $i++;
        }
    ?>
    Text file


    24022001||www.somedomain1.com||Some fake link1
    14012001||www.somedomain2.com||Some fake link 2
    04012001||www.somedomain3.com||Some fake link 3
    22022001||www.somedomain4.com||Some fake link 4
    21022001||www.somedomain5.com||Some fake link 5
    27012001||www.somedomain6.com||Some fake link 6
    05012001||www.somedomain7.com||Some fake link 7
    01022001||www.somedomain8.com||Some fake link 8
    11022001||www.somedomain9.com||Some fake link 9
    14012001||www.somedomain10.com||Some fake link 10
    22012001||www.somedomain11.com||Some fake link 11
    16022001||www.somedomain12.com||Some fake link 12
    17012001||www.somedomain13.com||Some fake link 13
    02012001||www.somedomain14.com||Some fake link 14
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  3. #3
    [Call me Bram] iBram007's Avatar
    Join Date
    Feb 2001
    Location
    Belgium
    Posts
    339
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This doesn't work very good, I only want the url's are sorted on date, the date must not be printed!

  4. #4
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Like I said before the date prints to show you that they are indeed in the correct order

    the dates are only printed to show you that the order is correct.

    I doubt you will find anyone willing to write complete 100% bug-free code for you for free, this works I tested it, it may need some minor adjustmenets to suit your needs, but I don't see anyone else knocking down your door to help, so I would take what someone has spent valuable time creating and work with it to make it work for your situation which it does, all you need to do is fix the part that prints the links to exclude the link I can do it in about 5 seconds. INstead of saying

    This doesn't work very good, I only want the url's are sorted on date, the date must not be printed!

    BTW here is the 5 seconds worth of changes I made to make it work for your situation

    PHP Code:
    printf('<a href="%s">%s</a> - %s<hr class=middenhcel size=1>%s'$links[$key]["url"], $links[$key]["url"], $links[$key]["desc"], "n"); 
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  5. #5
    [Call me Bram] iBram007's Avatar
    Join Date
    Feb 2001
    Location
    Belgium
    Posts
    339
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you
    I won't ask you stupid questions anymore

  6. #6
    [Call me Bram] iBram007's Avatar
    Join Date
    Feb 2001
    Location
    Belgium
    Posts
    339
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    this is the output of your script:
    http://www.bramstart.be/url/url2.php

    The url's aren't sorted on date...

  7. #7
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hmmm... This is the output on the page you sent us to, how is this not sorted by date. the first one is Jan 2 2001 and the last one is Feb 11 2001 and the rest are in date order. S owhat do you mena by?
    The url's aren't sorted on date...
    Code:
    www.somedomain14.com - Some fake link 14 - 02-01-01
    --------------------------------------------------------------------------------
    nwww.somedomain3.com - Some fake link 3 - 04-01-01
    --------------------------------------------------------------------------------
    nwww.somedomain7.com - Some fake link 7 - 05-01-01
    --------------------------------------------------------------------------------
    nwww.somedomain10.com - Some fake link 10 - 14-01-01
    --------------------------------------------------------------------------------
    nwww.somedomain2.com - Some fake link 2 - 14-01-01
    --------------------------------------------------------------------------------
    nwww.somedomain13.com - Some fake link 13 - 17-01-01
    --------------------------------------------------------------------------------
    nwww.somedomain11.com - Some fake link 11 - 22-01-01
    --------------------------------------------------------------------------------
    nwww.somedomain6.com - Some fake link 6 - 27-01-01
    --------------------------------------------------------------------------------
    nwww.somedomain8.com - Some fake link 8 - 01-02-01
    --------------------------------------------------------------------------------
    nwww.somedomain9.com - Some fake link 9 - 11-02-01
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  8. #8
    [Call me Bram] iBram007's Avatar
    Join Date
    Feb 2001
    Location
    Belgium
    Posts
    339
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm sorry...
    hope you won't getting angry now
    I'm using arsort() now instead of asort()...


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •