The forums have permanently moved to forum.kirupa.com. This forum will be kept around in read-only mode for archival purposes. To learn how to continue using your existing account on the new forums, check out this thread.


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