We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 44231
    • 126 Posts
    johnrobert27 Reply #1, 13 years ago
    hi there!
    I have this method of writing my queries,

    First:
    $path = MODX_CORE_PATH . 'components/mod1/';
    $result = $modx->addPackage('mod1',$path . 'model/','mod_');
     
     
    $output = null;
    $urlresult = "A";   
     
    /*for the A-Z drug search*/
    if(isset($_GET['alpha'])){
    if ((strlen($_GET['alpha'])!=null)||($_GET['alpha'])!=0){
    $urlresult = $_GET['alpha'];
    }
    }
     
    $query = $modx->newQuery('Tblbook');
            $query->select(array (
                'Tblbook.brand_name',
                'Tblbook.system_product_id',
                'Tblbook.system_brand_id',
                'TBOOKS.content',
                'TBOOKS.description',
                'TBOOKS.long_indication'
              
     
            ));
        
            $query->innerJoin('Tblbooks', 'TBOOKS', array(" Tblbook.system_brand_id = TBOOKS.system_brands_id")); 
            $query->where(array("Tblbook.brand_name:LIKE" => "$urlresult%"));
            $query->groupby('brand_name');
              
            $products = $modx->getCollection('Tblbook',$query); 
    


    Second:
    $search = $modx->query("SELECT b.form_class, a.system_brand_id, a.system_product_id, b.company, a.system_edition_id, a.brand_name, b.content, c.section1_id, c.section2_id, c.section3_id, c.section4_id,
    MATCH (tfv_records)AGAINST ('$xkeywordx' IN BOOLEAN MODE) AS relevance
    FROM mod_tfvrecords a, mod_tblcontents b, mod_tblproductcategory c
    WHERE MATCH (tfv_records)AGAINST ('$xkeywordx' IN BOOLEAN MODE)
    AND a.system_brand_id = b.system_brands_id
    AND a.system_product_id = c.system_product_id GROUP BY a.system_product_id HAVING relevance > 0.1 ORDER BY relevance DESC LIMIT 50");
    


    now my question is , what method is more optimize? what method is more convenient to use in modx?I having a hard time choosing with this method.

    can you give some advice? Im new in modx so I'm eager to learn new things in modx way smiley
    I hope you understand my problem!

    thanks!
      • 3749
      • 24,544 Posts
      I would say to try both methods and test the speeds, but Jason (OpenGeek) could give you a better answer.

      I find the xPDO methods a lot more convenient, especially when there are related objects, but it looks like you're more used to writing in SQL than I am, so it might be different for you.
        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
        • 2249
        • 60 Posts
        ashfinlayson Reply #3, 13 years ago
        In my experience MySQL queries ie your method 2, will always trump xPDO methods, especially if you're querying template variables.

        Check out Jason Cowards Executioner snippet if you haven't already, it shows you how long each of your snippets are taking to execute. Thats what made me favour the row sql query root over stuff like
        $modx->resource->getTVValue('nameoftv');


        http://jasoncoward.com/technology/2010/10/the-executioner-snippet.html

        Cheers
        Ash