We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 18367
    • 834 Posts
    Hi,

    I have information in another database that I either want to import into Modx or access the db via Modx.

    Then I obviously want to display the data in some useful presentation.

    The data is a list of businesses, names, addresses, contact details etc.

    Can anyone either point me in the direction of a really good tute on how to do this, or tell me how to do it?

    I’m guessing that getting the data out of the old db in a flat file and importing that into MODx somehow is the easiest option, but I don’t know how to do that.

    I’m not a programmer, so lots of detail and screenshots would be greatly appreciated.

    However, I have been known to write php code and make things work. I’ve hacked enough of Worpress’s labyrinthine files to have at least a cursory understanding of php.

    Also, should I use Ditto, Datagrid or is there some better option for manipulating and presenting data?

    Many thanks in advance for any assistance. grin

      Content Creator and Copywriter
      • 3749
      • 24,544 Posts
      If the data is in a MySQL database, you can just do the standard export and import it into the MODx database (using PhppMyAdmin for both). If not, you can export it to a CSV file using whatever tool you have in the database program and then import it into the MODx database using PhpMyAdmin.

      Once it’s in the MODx database, you can access the data with the MODx DBAPI, usually in a snippet.
        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
        • 28042 ☆ A M B ☆
        • 24,524 Posts
        I’ve even written a script to parse a really ugly text file data dump from an ancient MS-SQL embedded system that doesn’t have an official export function. It parses the file and forms insert SQL statements from each line. The fun part was that each field was on a single line, with the records separated by two line breaks; some lines had data for all fields, but many did not (the number of lines would vary from record to record, so no simple looping), so I had to parse for end-of-record as well as end-of-field. It was interesting  tongue

        The data is actually what is displayed by the extjs paging data grid with search that I’ve documented on my site. It’s also managed by the module documented in a different set of articles, although in the articles I use a more sane csv import.
          Studying MODX in the desert - http://sottwell.com
          Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
          Join the Slack Community - http://modx.org
          • 4041
          • 788 Posts
          My thoughts on this are:

          1. If you need to further manipulate the data in the already exisitng database as well as print the output in a MODx environment, some type of import is needed, which would require creating a custom import technique (as I am quite sure the DB fields between the two are diff) then a module to admin perhaps.

          2. To just print the data only, far easier to simply write a snippet to query the DB and then print the output in a document.

          :) my 2 cent
            xforum
            http://frsbuilders.net (under construction) forum for evolution
            • 18367
            • 834 Posts
            OK,

            I’ve managed to import the data into the MODx db via phpadmin. (It tells me everything’s ok, but really I have no idea if it is.)

            Now how do I access it, or get it to display?

            I need a really straightforward and simple explanation.

            Thanks
              Content Creator and Copywriter
              • 3749
              • 24,544 Posts
              Before you go any further, take a look at the table in PhpMyAdmin (select browse). If your import was successful, you should see all the data with one record per line and all the fields lined up (e.g. nothing but names in the name field).

                Did I help you? Buy me a beer
                Get my Book: MODX:The Official Guide
                MODX info for everyone: http://bobsguides.com/modx.html
                My MODX Extras
                Bob's Guides is now hosted at A2 MODX Hosting
                • 18367
                • 834 Posts
                Thanks Bob,

                sort of , see attached image.

                Not sure why I’ve got the extra step.

                  Content Creator and Copywriter
                  • 3749
                  • 24,544 Posts
                  Quote from: markg at May 20, 2008, 03:15 AM

                  Thanks Bob,

                  sort of , see attached image.

                  Not sure why I’ve got the extra step.

                  The structure looks reasonable. Now, click on the "browse" tab and see if the data looks all right.
                    Did I help you? Buy me a beer
                    Get my Book: MODX:The Official Guide
                    MODX info for everyone: http://bobsguides.com/modx.html
                    My MODX Extras
                    Bob's Guides is now hosted at A2 MODX Hosting
                    • 18367
                    • 834 Posts
                    Yep,

                    data is all there. :’(
                      Content Creator and Copywriter
                      • 3749
                      • 24,544 Posts
                      Great, now you just need to display it. It seems like MODx should have an easy way to do this. The DataGrid widget (http://modxcms.com/datagrid-widget.html) would do it, but I couldn’t find any "how to" documentation for it. A search of the forum for DataGrid will turn up a few examples that might get you started.

                      Another alternative is this snippet from OpenGeek:

                      <?php
                      $output= '';
                      $rowChunkName= 'tableRowChunk';
                      $sql= 'SELECT * FROM `table_of_data`';
                      $rs= $modx->db->query($sql);
                      if ($rs) {
                          foreach ($modx->db->getRow($rs) as $row) {
                              $modx->placeholders= array_merge($modx->placeholders, $row);
                              $output.= $modx->parseChunk($rowChunkName, $modx->placeholders, '[+', '+]');
                          }
                      }
                      return $output;
                      ?>


                      Change "table_of_data" to the name of your table.

                      You’ll need to create the rowChunkName chunk yourself. Hopefully, someone will chime in here with a working example of what that chunk should look like. Since I haven’t done it, I don’t want to guess and get you off on the wrong foot.

                      Hope this helps,

                      Bob
                        Did I help you? Buy me a beer
                        Get my Book: MODX:The Official Guide
                        MODX info for everyone: http://bobsguides.com/modx.html
                        My MODX Extras
                        Bob's Guides is now hosted at A2 MODX Hosting