Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    Regular Coder
    Join Date
    Sep 2009
    Location
    Calgary, Alberta
    Posts
    241
    Thanks
    48
    Thanked 3 Times in 3 Posts

    Sort ability help

    I am looking at trying to sort information on a sheet.. I have tried sort by.. group by I have remade my page 10 times... I just can't figure it out.

    this is what I need results of:

    11-23-2011

    record 1 Persons name | sold | Trade in | 11-23-2011
    record 2 Persons name | sold | Trade in | 11-23-2011
    as many records as there may be for this date etc..


    11-22-2011
    record 1 Persons name | sold | Trade in | 11-22-2011
    record 2 Persons name | sold | Trade in | 11-22-2011
    record 3 Persons name | sold | Trade in | 11-22-2011
    as many records as there may be for this date etc..
    etc..


    Right now all I can get is this..

    11-23-2011

    record 1 Persons name | sold | Trade in | 11-23-2011

    11-23-2011

    record 2 Persons name | sold | Trade in | 11-23-2011

    as many records as there may be for this date etc..

    11-22-2011

    record 1 Persons name | sold | Trade in | 11-22-2011

    11-22-2011

    record 2 Persons name | sold | Trade in | 11-22-2011

    11-22-2011

    record 3 Persons name | sold | Trade in | 11-22-2011

    as many records as there may be for this date etc..


    I hope this makes sense.>>

    I am trying to make a list that is sorted by the date. and list those sorted by that day .. and then go to the next day... etc..

    Thanks in advance, Slayer.

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    You can't do this directly in SQL. You order it by the date, and you need to use your language to split them into something readable. All you need is to set a variable before the loop, and update it with the iteration's record date. When it detects that the date has changed, it then provides a new div or table or whatever you using to split it up visually.

  • #3
    Regular Coder
    Join Date
    Sep 2009
    Location
    Calgary, Alberta
    Posts
    241
    Thanks
    48
    Thanked 3 Times in 3 Posts
    Wow... and I thought I was gonna loose you in what I said.. lol

    I now need to figure this out. "set a variable before the loop, and update it with the iteration's record date."

    Thanks for the help.

    Did I forget to say.. ME NOOB. I do not want it done for me.. just a lead to the direction of.

    Thanks,


    Slayer

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    PHP Code:
    $mLastDate null;
    print 
    '<div>';
    while (
    $row fetch($record))
    {
        if (
    $mLastDate != $row['date'])
        {
            
    // Date has changed.
            
    print '</div><div><h2>' $row['date'] . '</h2>';
            
    $mLastDate $row['date'];
        }
        ...
    }
    print 
    '</div>'
    Like so. I just called the method fetch since I don't know what database you are using. Similar principal applies if you are working with tables.

  • Users who have thanked Fou-Lu for this post:

    SlayerACC (11-24-2011)

  • #5
    Regular Coder hinch's Avatar
    Join Date
    Sep 2005
    Location
    UK
    Posts
    923
    Thanks
    25
    Thanked 80 Times in 80 Posts
    I do something similar on a report.

    What I do is i do a primary select first to get all the dates with records in the db sort of like a group by date or a select unique

    then for each itteration of that loop I call a sp that generates the entries for that date but in your case you could do a sub select of entries by date
    A programmer is just a tool which converts caffeine into code

    My work: http://www.fcsoftware.co.uk && http://www.firstcontactcrm.com
    My hobby: http://www.angel-computers.co.uk
    My life: http://www.furious-angels.com

  • #6
    Regular Coder
    Join Date
    Sep 2009
    Location
    Calgary, Alberta
    Posts
    241
    Thanks
    48
    Thanked 3 Times in 3 Posts
    Hello and thank you all for your help.

    Fou-Lu you are awesome. You inspire those as my self to want to learn more and be able to help like you do.


    With your last post I got it working.. but I ask you if you can ..

    Explain how it works. so that I understand, and can use this type of procedure again in the future.

    PHP Code:
    $mLastDate null;
    print 
    '<div>';
    while (
    $row fetch($record)) 
    {
        if (
    $mLastDate != $row['date'])
        {
            
    // Date has changed.
            
    print '</div><div><h2>' $row['date'] . '</h2>';
            
    $mLastDate $row['date'];
        }
        ...
    }
    print 
    '</div>'
    Thank you again ..

    Slayer.

  • #7
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    It simply tracks the known date, and if the date changes it forces a structural change in the HTML so that we can see it differently. The above will actually leave a bad entry in place since it starts at null which your date probably never is, so the first thing it does is open and closes a div before creating a new one. A few ways around that one too, I'd check if the $mLastDate is null and if it is, I wouldn't close and open a new div, but just print the date. Otherwise, close the div open a new one and print the date.


  •  

    Posting Permissions

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