Can we see your page with ’single characters’ somewhere? I’d be interested to see the page source. Might give a clue to what’s going on.
This kind of thing :-
B
o
b
S
m
i
t
h
is caused because you are returning a string to the datagrid widget, it must be a resource(i.e from MYSQL) or an array. It prints it like that because a string is just an array of characters,
you need to return ’names = array( 1=> ’Bob Smith’, 2 => ’Fred Jones’)’ etc. not just ’Bob Smith’. Having said that this should work from a @SELECT binding without further ado, if you are using @EVAL here be sure to co-erce your return values into an array before returning.
Use MODx, or the cat gets it!
-
☆ A M B ☆
- 2,475 Posts
Mmm... I’ll try this again. I’m quite sure my MySQL is correct... I’m very comfortable with MySQL and I’ve tested the query in the MySQL command line... in any case, the whole page explodes with a huge MODx error if the SQL has an error.
Anyone want to update that Wiki page I started? (please, oh, please...)
The above DEFAULT VALUE call: @SELECT alias, pagetitle FROM modx_site_content WHERE template = 11
changed to my template: @SELECT alias, pagetitle FROM modx_site_content WHERE template = 6
and with this:
Column Name: alias, pagetitle
Field Names alias, pagetitle
Works perfect. Sweet thing!!
-
☆ A M B ☆
- 2,475 Posts
Ok, this is driving me insane... sweet thing? No, this is more like what Borat would call "a pain in my assholes". Can someone please point out how obliviously stupid I’m being? I’m getting the same old problem with a single letter in each row.
Here’s what I got:
===My Template Variable====:
Input Type: Text
Input Option Values: --blank--
Default Value:
@SELECT pagetitle, alias FROM site_content WHERE parent=’129’
Widget: Data Grid
Widget Properties:
Column Names: pagetitle,alias
Field Names: pagetitle,alias
Column Widths: 50
Column Alignments: left
Column Colors: -- blank --
Column Types: text
[... blank ...]
MODx version 0.9.6.2
Why doesn’t this work? I have even pasted my SQL query into PHPMyAdmin and I get 9 rows of results. I’ve cleared MODx’s cache and my browser cache... I’ve cut off the WHERE statement from my query and I’ve renamed my column names (so I know the page is refreshing), and I still get the same stuff: one letter per row.
PM me some login details and I’ll have a look for you when I get back from work tonight.
So I have had a look at Everettg_99’s server and I can now see where it’s going wrong.
The default @SELECT works as long as no value is entered into the TV when editing the document.
Here’s where the problem occurs. When you assign a value to the TV the value is stored in the database as a string exactly like it is (or as a comma delimited or a string with values delimited by || in case of multiple values), so when the datagrid widget receives this value it will treat it as an array of single characters.
The datagrid expects either a valid sql resource or a proper array. Setting a value for the TV will normally only return a string, except in some cases when using @ Bindings. @SELECT for instance, or a properly constructed @EVAL. The latter you can try by filling in this into your TV
@EVAL return array( array(’1’,’One’), array(’2’,’Two’), array(’3’,’Three’) );
If your aim is to just use the default value (the @SELECT) than you just need to make sure to leave the TV empty in the document. I’ve used it like this on occasion as a convenient way of displaying DB data, however I hacked the Template Vars manager files to have an extra input type that simply hides the TV from the documents so that no one can accidentally enter values. The same can be achieved with the ManagerManager plugin.
@Everettg_99 Booyakasha!!!

Sorry!