We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 8962
    • 7 Posts
    Hi there,
    I am trying to do the following thing:

    I need to make a database with a table that looks like that (example):

    table name: calling cards

    calling from | calling to | price per minute | link to image of the calling card |
    -----------------------------------------------------------------
    U.S.A | London | 19 cents | /images/callingcard/example.gif |
    -----------------------------------------------------------------
    Israel | Europe | 15 cents | /images/callingcard/example2.gif |
    -----------------------------------------------------------------

    As you can see, I am trying to do 2 things:

    1) I know how to make a table like that, but my question is - is it possible with modx to create a table like that
    and change it easily, for example - just going with the mouse and visually change something? like WYSIWYG but
    for databases?

    2) How to create a link to this table using modx in the most simple and right way?

    I hope I explained my self good enough..

      • 8962
      • 7 Posts
      Thank’s for the fast reply,
      another question:
      how do I use dbapi with modx?
      here is a link:
      http://wiki.modxcms.com/index.php/API:DBAPI

      I know it is a very simple question, but I don’t understand this:
      I create a new database with a new table inside it (on Localhost).
      How exacly do I show this table using modx? I tried using datagrid widget and I couldn’t find out how it is done.

      I also tried to connect to my database using mysql connect string in a NEW-DOCUMENT that I created in modx, but I don’t think this is the way to do it... (doesn’t work).
      I know it is a very simple things, but I don’t understand it...
      Thank you!!
        • 3749
        • 24,544 Posts
        The DBAPI functions need to be used inside a MODx snippet, which means that to use them, you need to be able to write PHP code.

        Basically, in your snippet, you just set the variables you need for the API function and then call it using something like the examples you see at the DBAPI link in your message. I thnk you will also have to know how to write a MySQL query if you want to create or alter tables.

        I hope this makes sense.

        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
          • 8962
          • 7 Posts
          Hi,
          well,
          I had tried using the dbapi with snippest, but I get this error:
          Parse error: syntax error, unexpected T_VARIABLE in C:\wamp\www\modx\manager\includes\document.parser.class.inc.php(769) : eval()’d code on line 13


          I am sending a "print-screen" picture so you might understand what I did wrong.
          I created a database name: call
          a table name: call3

          HELP :’(
            • 28042 ☆ A M B ☆
            • 24,524 Posts
            You’re missing a semicolon on your disconnect line.
              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
              • 8962
              • 7 Posts
              Thank’s, I took this example from the wiki dbapi (http://wiki.modxcms.com/index.php/API:DBAPI:connect) and I didn’t noticed that there was a missing semicode.

              Another question - Now that I know how to connect to a database with the DBAPI, how can I show a table from the specific database?
              Is it exacly like mysql language, so I can learn mysql lang and imply it on modx?

              can you please give me an example of how to show a table from a specific database?
              thank’s again!!!
                • 28042 ☆ A M B ☆
                • 24,524 Posts
                Once you connect you can use
                select($fields = "*", $from = "", $where = "", $orderby = "", $limit = "")

                so you could have
                $table = 'mytable';
                $results = $modx->select('*', $table);

                then do whatever with the results; there are other dbapi functions for dealing with a select query resultset.
                  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
                  • 8962
                  • 7 Posts
                  What is the chance you will give an example how to write it from the begining to the end (inside a snippet named "database".

                  my database name: call
                  table name: call3

                  the table is attached (screen-captured of phpmyadmin)
                  thank you!