I’m attempting to display a simple table of data in a MODx page. I’ve created a TV using the datagrid widget along with a basic page that is set to display the TV. The data is coming from a MySQL database with a very basic query i.e. SELECT * FROM databasename.tablename.
When I call the page the table appears with the correct headers (from the database) but no data is displayed. The number of lines displayed in the table seems to be controlled from the query, i.e. if I add a LIMIT statement the number of lines in the blank table follows the LIMIT value. The MySQL query works fine if I run it in phpMyAdmin. Many of the other parameters in the widget seem to be working fine as I can add and format header and footer text, etc. Also, there are no error messages.
Any ideas on what could be stopping the data from displaying?
Thanks,
Mike
SOLUTION --
Solved it myself - silly mistake really - you have to list the field names that you want displayed in the widget parameters. Even if you use a SELECT * statement you still have to list each field you want displayed.
Having solved that I now find that the pager doesn’t work! I’ll start a new thread for that if I get stuck.
Having to specify the field names is a pain and limits the flexibility of this widget. If you want the widget to display all the fields in the table you need to modify datagrid.class.php and datasetpager.class.php as follows:
AMEND THIS: $ row = $ this-> _isDataset? mysql_fetch_assoc ($ this-> ds): $ this-> ds [$ r];
TO READ: $ row = $ this-> _isDataset? mysql_fetch_array ($ this-> ds): $ this-> ds [$ r];
i.e. change mysql_fetch_assoc to mysql_fetch_array
A better solution would be to have an option to enter ALL or *, etc. in the field name option to see all the fields displayed but I don’t think that exists.