MODX Revolution 2.2.4-pl (traditional)
I'm a frustrated xPDO newbie, attempting to create an A-Z list from a custom association members table. The links from list will serve as an alphabetical filter to an association members list.
`Members` (
`MemberID` int(11) NOT NULL AUTO_INCREMENT,
`Surname` varchar(255) DEFAULT NULL,
`MemberName` varchar(255) DEFAULT NULL,
`Status` varchar(100) DEFAULT NULL,
`Seal` varchar(10) DEFAULT NULL,
`CompanyID` int(11) DEFAULT NULL,
PRIMARY KEY (`MemberID`)
) ENGINE=MyISAM;
In MySql this would be a simple
"SELECT DISTINCT UPPER(LEFT(Surname,1)) as letters FROM Members ORDER BY letters”;
How do I do this with xPDO?
I've looked at various examples but my current comfort level with xPDO is preventing me getting anywhere with this.
A few lines of code to get me started would be greatly appreciated.
Thanks
Give a man the answer, and he’ll only have a temporary solution. Teach him the principles that led you to that answer, and he will be able to create his own solutions in the future.
Found the answer here:
http://rtfm.modx.com/display/xPDO20/xPDO.query. At least it does the job for me.
Give a man the answer, and he’ll only have a temporary solution. Teach him the principles that led you to that answer, and he will be able to create his own solutions in the future.
Quote from: opengeek at Jan 22, 2013, 03:55 PM
If you have created an xPDO model for this table, you could do something like this using the classes/map you generated to build the query with the API (xPDOQuery):
$query = $modx->newQuery('Members');
$query->distinct();
$query->select(array(
'letters' => "UPPER(LEFT(Surname, 1))"
));
$query->sortby("letters", 'ASC');
Although I have the query working using a different approach. This example crashes my server any idea what the reason may be?
Give a man the answer, and he’ll only have a temporary solution. Teach him the principles that led you to that answer, and he will be able to create his own solutions in the future.
Wild guess would be that you need to have primary key field selected also, so for the select array add the PK field (most likely id or idx etc...).
Thanks Jason, this PDO lark has a very steep learning curve, but eventually with help I'll get there. I am a mega personal genealogical project that I want to develop with MODx and PDO, but that will need to wait for a while.
I really believe that MODx is great, the problem I, and others have is the lack of clear tutorials. This isn't mean as a criticism as I have been guilty of the same in my areas of expertise. Often we are too familiar with our material and consequently tend to miss small details that are needed for a novice to get started with the process when preparing tutorial packages.
Give a man the answer, and he’ll only have a temporary solution. Teach him the principles that led you to that answer, and he will be able to create his own solutions in the future.