...

View Full Version : Sort ability help



SlayerACC
11-23-2011, 09:38 PM
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.

Fou-Lu
11-23-2011, 10:19 PM
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.

SlayerACC
11-23-2011, 10:53 PM
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

Fou-Lu
11-23-2011, 11:22 PM
$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.

hinch
11-24-2011, 02:15 PM
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

SlayerACC
11-24-2011, 02:26 PM
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.



$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.

Fou-Lu
11-24-2011, 02:40 PM
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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum