Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-23-2011, 08:38 PM   PM User | #1
SlayerACC
Regular Coder

 
Join Date: Sep 2009
Location: Calgary, Alberta
Posts: 222
Thanks: 45
Thanked 3 Times in 3 Posts
SlayerACC is an unknown quantity at this point
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.
SlayerACC is offline   Reply With Quote
Old 11-23-2011, 09:19 PM   PM User | #2
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,635
Thanks: 4
Thanked 2,448 Times in 2,417 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
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.
Fou-Lu is offline   Reply With Quote
Old 11-23-2011, 09:53 PM   PM User | #3
SlayerACC
Regular Coder

 
Join Date: Sep 2009
Location: Calgary, Alberta
Posts: 222
Thanks: 45
Thanked 3 Times in 3 Posts
SlayerACC is an unknown quantity at this point
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
SlayerACC is offline   Reply With Quote
Old 11-23-2011, 10:22 PM   PM User | #4
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,635
Thanks: 4
Thanked 2,448 Times in 2,417 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
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.
Fou-Lu is offline   Reply With Quote
Users who have thanked Fou-Lu for this post:
SlayerACC (11-24-2011)
Old 11-24-2011, 01:15 PM   PM User | #5
hinch
Regular Coder

 
hinch's Avatar
 
Join Date: Sep 2005
Location: UK
Posts: 921
Thanks: 25
Thanked 79 Times in 79 Posts
hinch is on a distinguished road
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
hinch is offline   Reply With Quote
Old 11-24-2011, 01:26 PM   PM User | #6
SlayerACC
Regular Coder

 
Join Date: Sep 2009
Location: Calgary, Alberta
Posts: 222
Thanks: 45
Thanked 3 Times in 3 Posts
SlayerACC is an unknown quantity at this point
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.

Quote:
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.
SlayerACC is offline   Reply With Quote
Old 11-24-2011, 01:40 PM   PM User | #7
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,635
Thanks: 4
Thanked 2,448 Times in 2,417 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
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.
Fou-Lu is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 01:48 PM.


Advertisement
Log in to turn off these ads.