We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 14214
    • 299 Posts
    I love MODX and truly MODX gives me a lot of power.

    I am not a developer by any means, but using MODX I have designed and created close to 100 websites - a few of them high traffic and well performing websites - without knowing any programming language outside of HTML/CSS. While I am not the most active person in the forums I am a regular promoter of the platform to users of all skill levels even though I am always in fear that I am letting them in on my little secret!

    Any way I am in need of some assistance and I hope and I hope you can support me. I created two tables within the same DB as MODX with some various bits of information that I wish to pull into (and likely cache) my MODX resource. My goal is to create a TV for which I will place an ID code then using a snippet I wish to pull results from a certain DB column.

    There will be two flavors of this so I will likely need two snippets. The first to pull all matching entries for the TV-entered ID code and place results in table rows that I will template.

    The second flavor, from a second table will only contain a single matching DB row and I wish to pull the data from a specific column and display it wherever in the document a specific placeholder.

    Probably really simple for some of you more experienced people, and you probably wonder how I have survived without knowing these basics - the answer is it is time to learn.
      • 28042 ☆ A M B ☆
      • 24,524 Posts
        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
        • 14214
        • 299 Posts
        Thanks Susan, I followed the info at Bob's site and got lost. I wasn't able to follow it.

        I've been looking at MIGxDB and that too has me a bit lost.
          • 3749
          • 24,544 Posts
          The method at my site for custom DB tables is not as complicated as it looks, you just have to follow the steps. You're ahead of the game in that you've already created the tables. Following the steps in the article will automatically create the class and map files that let you use xPDO methods with your custom tables.

          That said, you don't have to do it that way. The point of the method I describe is that you can then use xPDO to handle getting and setting the data for you, but in a snippet, the $modx variable is a handle to the MODX database. As long as your tables are in there, you can write your own queries using PDO or MySQL if you want to, xPDO is just a lot more convenient.
            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
            Well, if you do want to use regular PHP mysqli queries, you have to make a new connection to the database. MODX initiates a PDO connection right away, so PDO queries work out-of-the-box. But it is worth the time to learn how to create the class and map files and use the xPDO API methods.
              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
              • 4172
              • 5,888 Posts
              Quote from: jisaac at Jul 24, 2014, 06:47 PM
              Thanks Susan, I followed the info at Bob's site and got lost. I wasn't able to follow it.

              I've been looking at MIGxDB and that too has me a bit lost.

              To get the idea, I would recommend doing that tutorial:
              http://rtfm.modx.com/extras/revo/migxdb/migxdb.tutorials/migxdb.create-doodles-manager-with-help-of-migxdb
                -------------------------------

                you can buy me a beer, if you like MIGX

                http://webcmsolutions.de/migx.html

                Thanks!
                • 14214
                • 299 Posts
                Guess it just comes down to the fact I don't know PHP so even wrapping my head around the PDO means I should have some basic understanding.
                  • 3749
                  • 24,544 Posts
                  It's going to be tough to deal with custom database tables without knowing some PHP. wink

                  BTW, there's a nice PHP primer in the Appendix of my book that I think is a good way to get started for PHP newbies: http://modx.com/learn/modx-books/modx-the-official-guide/
                    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
                    If you've done any programming at all, PHP shouldn't be to difficult to pick up.

                    The one thing that it is absolutely essential to study and study well is how to write secure code. You can't just take any old input you get and throw it at the database. You have to check it to make sure it's generally what you are expecting to get, and then "escape" it so that even if somebody does sneak something nasty through, it won't do anything.

                    https://www.addedbytes.com/articles/writing-secure-php/
                    http://rtfm.modx.com/revolution/2.x/developing-in-modx/basic-development/snippets
                      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
                      • 39404
                      • 175 Posts
                      stalemate resolution associate Reply #10, 12 years, 2 months ago
                      Quote from: BobRay at Jul 25, 2014, 04:08 PM
                      It's going to be tough to deal with custom database tables without knowing some PHP. wink

                      BTW, there's a nice PHP primer in the Appendix of my book that I think is a good way to get started for PHP newbies: http://modx.com/learn/modx-books/modx-the-official-guide/

                      jisaac,

                      I agree with Susan that you should write secure PHP.

                      I also would fully recommend getting Bob's book, which will save you hours of headaches in getting up to speed. I got into MODX about 3 years ago and when I heard there was a book coming out, I'm sure I was one of the first to order it. 3 years later, I can assure you that it is not a purchase I regret; to put it another way, if you look at the number of people that Bob and Susan have helped, and imagine the brain power behind what Bob's written, it's like having Bob walk you through MODX from an objective insider's point of view.

                      Regards,
                      Tom