Everybody! This is important. In a few days, these forums will be moving over to using the totally sweet Discourse platform. To ensure this migration happens smoothly with no loss of content, these forums are currently in a read-only mode. I do apologize for the inconvenience.

There is never a good time to turn the forums off for an extended period of time, but I promise the new forums will be a billion times better. I'm pretty sure of it.

See you all on the other side in a few days, and if you have any (non-technical) questions, please e-mail me at kirupa@kirupa.com. For technical questions, try to find a tutorial that corresponds to what you are looking for and post in the comments section of that page.

Cheers,
Kirupa

Results 1 to 5 of 5

Thread: PHP sorting

  1. #1

    PHP sorting

    hello guys, long time i haven't posted.

    I create a while loop in which XML files are read from a folder. each XML file has information about a car, like Year, Model, Mileage, etc.

    When they are displayed on the page (while loop), they are displayed from oldest to newest. Is there a way I can make them displayed from newest to oldest, sort by Price or sort by Year? I know there is the SORT function, but I read about it and it LOOKS like it only works with arrays.

    PHP Code:
    $handle opendir($dirAutomobiles);
    while((
    $file=readdir($handle)) !== FALSE) {
    if(
    is_dir($dirAutomobiles $file)) continue;
    if(!
    eregi(".xml$"$file)) continue;

    $automobileFile simplexml_load_file($dirAutomobiles $file);

    echo 
    $automobileFile->year;
    echo 
    $automobileFile->make;
    echo 
    $automobileFile->model;
    echo 
    $automobileFile->price;

    "You are playing a very dangerous game"
    "Change always is"

    Creativo Development

  2. #2
    Quote Originally Posted by imagined View Post
    I know there is the SORT function, but I read about it and it LOOKS like it only works with arrays.
    so why don't you put your stuff in array 1st?

  3. #3
    I know its kinda silly. But I always tried to stay away from arrays. I think it's because when I started learning programming I was afraid of arrays 'cause i thought they were very complicated (multidimensional arrays and stuff).

    But since I got this problem to solve, I had no option but to go for arrays, and now that I'm looking into it, there are not as complicated as i used to think. I already succeded in placing the contents of the while loop in an array. Now I'm trying to display the contents of the array using a for loop. And then I will see how I can sort the results.

    When Im done with this I will try to post the solution. If I have problems in the sort part, I will post it too.

    Thanks puppy!

    Leo
    PS: Is that your nick because of Nacho Libre? hehe
    "You are playing a very dangerous game"
    "Change always is"

    Creativo Development

  4. #4
    Haha, arrays are the beauty of life. They aren't that complicated. They can get complicated, but by the time they get complicated, you're used to them and the logic just makes sense
    got pwnt?

  5. #5
    yes, i am also starting to fall in love with arrays. :p

    im reading on the sort subject. is there a way to sort a date?
    example, 2007-04-05?
    "You are playing a very dangerous game"
    "Change always is"

    Creativo Development

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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

Home About kirupa.com Meet the Moderators Advertise

 Link to Us

 Credits

Copyright 1999 - 2012