Complex sort?

10 posts by 3 authors in: Forums > CMS Builder
Last Post: February 16, 2009   (RSS)

Hi Dave,

I have a table (called registration) I'd like to sort using fields I've created in each record. One of the fields is the name of a class (name) and the others, the class presentation dates, actually consists of several similar fields (list1, list2,...list50). Some of the classes have several (up to 50) dates for the same class.

What I'd like to do is list the class by date with the oldest (first) date at the top. So what the user would end up seeing is a "Schedule of Classes" with the date of the class listed on the left and the name of the class on the right. I've already figured out the table and how to list them it's just a matter of getting them to list by date, even though a record could contain more then one date.

The dates (field=list1, list2,...) is in the format "Jan 5 thru 16, 2009" and would only need to see the first date (Jan 5). An example listing would be: "Jan 5 thru 16, 2009 /30 Firearms Instructor" The /30 is the number of 'seats' available and is part of the date field and if that would cause a problem, I can take it out (with some another code I found).

I'm pretty sure the code for the sorting (sql) probably goes in the top portion under the 'where' => but do not know how I would loop through the dates to put them in the proper order order.

You helped me once before looping through the dates:

...
<?php foreach (range(1,50) as $num): ?>
<?php if ([url "mailto:!@$registrationRecord["list$num"]!@$registrationRecord["list$num[/url]"]) { break; } ?>
<?php echo $registrationRecord["list$num"] ?><br/>
<?php endforeach ?>
...

which worked great for listing all the dates by record but now I'm lost. I checked the php web site under 'sort' but just got more confused.

Any suggestions?

TIA!

Eric

Re: [eduran582] Complex sort?

By Dave - February 6, 2009

Hi Eric,

Do you have a sample url that shows the dates listed and a mockup that shows how you want them listed?

Are the dates entered in chronological order? And are they entered as date fields or text fields? And do you want to sort always by "list1" or sometimes by different date fields?

Basically, you can specify a list of fields to sort by like this in the viewer options:

'orderBy' => "date DESC, name",

But it sounds like you need something more complicated than that. Let me know some more details and I'll try to help.
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] Complex sort?

Hi Dave,

Geez, that was quick! I guess you live in front of a computer too [:)]

Here's a url to what I've come up with so far: http://alamedacountysheriff.org/_rtc2009/classes/registrationList.php

A result would look something like this: http://alamedacountysheriff.org/_rtc2009/scheduleDetail.php?viewer.php?page=1

I'm trying to get away from having the user enter the information, as in the second example.

All the dates entered under each record are in chronological order (the starting date in some cases) and all are entered as text fields. The first available date would always be "list1". As the user updates with newer dates, they could either add on to the existing dates or delete the oldest and replace with newer; either way, the first date would always be "list1".

If this issue goes into the "custom programming" area, please let me know. I have no problem utilizing and paying for your great talent!

Let me know if you need any other information.

Eric

Re: [eduran582] Complex sort?

By Dave - February 9, 2009

Hi Eric,

Thanks for the link. Are the dates just entered in regular text fields? If so it's hard to sort on them because PHP/MySQL doesn't understand them as dates unless they're in a specific date field.

What about sorting them with "dragSortOrder" and having newly added records added to the top? That way new records always show first and the user can change the order of records if needed by dragging them around?

Or another option, have a date field that is used for sorting. So "Start Dating" date could be stored as a date and we could sort on that.

Would either of those work?
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] Complex sort?

Hi Dave,

The date/available seats field is a text field. The "seats available" would be changed by the person confirming the registration.

I was thinking the same thing; have a separate 'date' field and use the sort based on that field. I'll figure out something for the "seats available" part. If that were the case (separate date field), when it goes through and creates the "list", would the rows containing the dates and other information end up accending (oldest date on top)?

My goal is to have that "Schedule of Classes" automated based on the information the manager adds to each class. Just getting it in order is the problem. I'll add the date field and see what happens [tongue]

As usual, thanks for all the help!

Eric

Re: [eduran582] Complex sort?

By Dave - February 9, 2009

Hi Eric,

Yes, if you add a date field and then sort by that like this:

'orderBy' => " `myDateField` DESC ",

Then the newest records will show up first. You can also set the sort order under: Admin > Section Editors
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] Complex sort?

Thanks, Dave.

I think I've run into a snag; there are several dates (at least more then one) for most of the classes. So if Iadd several date fields, I'm not sure it will work. I was going to try Date-1 up to Date-50 (date fields) replacing the existing text fields that contain a date. With that many possible dates for each class, how would I set the 'orderBy' or even the Admin Section editor? Would it be something like 'orderBy' => " Date-1, Date-2, Date-3...Date-50 ", ?

[crazy]One other thought.... maybe I'll just create another (numeric?) field and have the manager convert each date and THEN order it on that field (similar to above)? That way I wouldn't have to change all those dates.

Thanks. Hope you like challenges [cool]

Eric

Re: [eduran582] Complex sort?

By Dave - February 10, 2009

Hi Eric,

Yea, I'd recommend creating one field for sorting. Or using the "dragSortOrder" field, or a single date field and sort on that.

You can set the sorting for the admin under: Admin > Section Editors > Sorting (tab)

Hope that helps!
Dave Edis - Senior Developer
interactivetools.com

Re: [eduran582] Complex sort?

By ross - February 16, 2009

Hi Eric

That's great! I am glad you got that working. I'll make sure Dave knows :). Feel free to post anymore questions you have.
-----------------------------------------------------------
Cheers,
Ross Fairbairn - Consulting
consulting@interactivetools.com

Hire me! Save time by getting our experts to help with your project.
Template changes, advanced features, full integration, whatever you
need. Whether you need one hour or fifty, get it done fast with
Priority Consulting: http://www.interactivetools.com/consulting/