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

    I would like to do a table query from the database with Table Sort feature on output. Somehow I can seem to successfully query the database for desire results.

    I’ve have over 1,000 links (blog roll from wordpress), I’ve export out of Wordpress database and import into Modx database as a table. name = "wp_links"

    How do I do about querying the database and output these links, name, desc, to a modx page?? and able to sort in on the result page.

    Could you provide some code sample?

    Thank you in advanced,

    -Tyler (modx newbiee)
      • 9207 ☆ A M B ☆
      • 2,475 Posts
      This is really a MySQL question. Is it an option to sort the query over in the WordPress database? I’m guessing you did this as a "INTO OUTFILE" type of query, yes?

      You can load data from a file (csv, for example)... it’s easier if you have selected the columns you needed, but this isn’t required (you can omit columns). The reciprocal operation is often a "LOAD DATA INFILE" option. Look up both of them and you should get some ideas of how to build your queries. Without knowing what columns and tables you have (and what data is in them), it’s difficult to answer your question explicitly.
        • 3749
        • 24,544 Posts
        If you’re using the MODx DB API, make sure the new table has the same prefix as the rest of the MODx tables. Then leave off the prefix when you call the DB API functions.

        http://wiki.modxcms.com/index.php/API:DBAPI:select
          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
          • 4310
          • 2,310 Posts
          Have you seen the Custom DB table to custom placeholders Wiki article?
          Sounds like it might help.
            • 30888
            • 4 Posts
            bunk58: thanks guys.. this is the best support ever!!!

            this website did the trick
            http://wiki.modxcms.com/index.php/DB_query_and_Placeholders

            The reason I was the errors is because I don’t create the chuck with the same name.. doh..

            Snippet code (php) - [[wp_links]]:

            <?php
            $output = ’’;//create variable for holding the output
            $sql = $modx->db->query( ’SELECT * FROM `modx_wp_links` LIMIT 0, 1000’);//define the DB query, in this case the table is named ’tblprojects’, add WHERE AND etc. as needed
            $resultArray = $modx->db->makeArray( $sql );//put it into an array
            foreach($resultArray as $item)//go through each record in the array
            {//start looping through the data array
            $params[’link_id’]=$item[’link_id’];//set the placeholders, the $params sets the name of the placeholder, the $item is the field name from the DB table
            $params[’link_name’]=$item[’link_name’];
            $params[’link_url’]=$item[’link_url’];
            $output.=$modx->parseChunk(’URLTpl’, $params, ’[+’, ’+]’);//define the chunk name and process the content, here it’s ProjectTpl which has the placeholders for the data
            }//finish looping through the data array
            return $output;//now return the output from the processed chunk
            ?>

            Chuck: {{URLTpl}} -> chunk referred to in the snippet:
            <h3>[+link_id+]</h3>
            <p> [+link_name+]

            [+link_url+]</p>

            Add this chuck to my template:
            [[wp_links]]
            {{URLTpl}}

            --------------------------------------

            And drumroll.. data from the wordpress start showing up... yuppie!!!

            now on to creating a local community site with restaurant reviews, map, guide ect.... this is sweet

            did u mention you guys/gal here rock!! smiley

            -Tyler
              • 30888
              • 4 Posts
              Ok I got it working the way I want, but now...

              from wordpress blogroll code
              <?php wp_list_bookmarks(’title_before=<h2>&title_after=</h2>&categorize=1&category=67&order=asc’); ?>

              this produce the result of the blogroll of the (category 67)

              Result = nice display like this

              Email <- category 67

              * AOL Webmail <- links inside that category
              * Gmail <- links inside that category
              * Gmail Modes <- links inside that category
              * Guerrilla Mail <- links inside that category

              From wordpress I’ve exported these three tables
              wp_links -> modx_wp_links
              wp_term -> modx_wp_terms
              wp_term_relationships -> modx_wp_term_relationships

              I found this on codex wp table relationships mapping, but have no clue how to join/combine them
              http://codex.wordpress.org/images/8/83/WP_27_dbsERD.png
              http://codex.wordpress.org/Database_Description/2.5

              I current run a site lrwv.com -> it contain over 4,000 links and we’re adding more each day.. currently it use wp link manager, but the database query is soooo slow.. that why we’re moving it to modx..

              How do i join the table or making it so it will equal the result like my wp blogroll..

              category A
              * links 1
              * links 2
              * links 3
              * links 4

              category B
              * links 1
              * links 2
              * links 3
              * links 4

              Thanks again in advanced,

              -Tyler