SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Member
    Join Date
    Aug 2003
    Location
    California
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Help with some script (filestore) from Kevin Yank's book

    I'm trying to get files in the filestore to output in alphabetical order. Unfortunately, when I add "ORDER BY filename" to the $sql function, I don't get the desired output.

    This is the code I'm trying to achieve output in alphabetical order:

    // User is retrieving a file
    $sql = "SELECT filename, mimetype, filedata
    FROM filestore WHERE ID = '$id' ORDER BY filename";
    $result = @mysql_query($sql);
    if (!$result) die('Database error: ' . mysql_error());

    If someone wouldn't mind helping me out here with a referral to a specific tutorial, or just a quick note to tell me where I'm going wrong, I'd appreciate it.

    Thanks in advance!

  2. #2
    SitePoint Wizard mark_W's Avatar
    Join Date
    Mar 2004
    Location
    West Midlands, United Kingdom
    Posts
    2,631
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    maybe try :

    PHP Code:

    // User is retrieving a file
    $sql "SELECT filename, mimetype, filedata
    FROM filestore WHERE ID = '
    $id' ORDER BY filename DESC";
    $result = @mysql_query($sql);
    if (!
    $result) die('Database error: ' mysql_error()); 
    if that lists backwards (z-a) try :

    PHP Code:

    // User is retrieving a file
    $sql "SELECT filename, mimetype, filedata
    FROM filestore WHERE ID = '
    $id' ORDER BY filename ASC";
    $result = @mysql_query($sql);
    if (!
    $result) die('Database error: ' mysql_error()); 
    HTH

  3. #3
    SitePoint Member
    Join Date
    Aug 2003
    Location
    California
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That should work nicely, but it's not.

    Do you have any other thoughts?

  4. #4
    $this->toCD-R(LP); vinyl-junkie's Avatar
    Join Date
    Dec 2003
    Location
    Federal Way, Washington (USA)
    Posts
    1,526
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The only reason I can think of that your original code wouldn't work correctly is if you have leading blanks, unprintable characters or something like that in the filename field. What does your output look like?
    Music Around The World - Collecting tips, trade
    and want lists, album reviews, & more
    Showcase your music collection on the Web

  5. #5
    SitePoint Member
    Join Date
    Aug 2003
    Location
    California
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The output looks just as it would if I hadn't applied the ORDER BY clause. For example, if I upload d.txt, c.txt, b.txt, and a.txt, the files appear in that order even with the ORDER BY clause.

    I have checked for whitespace, but I am not seeing it.

    I shall get back to the drawing board.

    Thanks!

  6. #6
    SitePoint Zealot devscripts's Avatar
    Join Date
    Sep 2004
    Location
    ur monitor
    Posts
    175
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    $sql = "SELECT filename, mimetype, filedata
    FROM filestore WHERE ID = '$id' ORDER BY filename";
    "None of you [truly] believes until he wishes for his brother what he wishes for himself." By The one and Only Prophet Mohammed (Peace and blessings be upon him)


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
  •