We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 27449
    • 211 Posts
    Hello,
    I have a query in a file ../assets/modules/resorts/update.php
    but the query doesn’t show anything :S

    the code of the query it is:
    $mydb= new DBAPI();
    $mydb->connect($host=’localhost’,$dbase=’oprc’, $uid=’root’,$pwd=’’);
    $ds ="SELECT * FROM `pais` WHERE `continente`=’".$_GET[’continente’]."’";
    $result = $mydb->query($ds);
    while ($linha = mysql_fetch_array($result)) {
    echo "<option value=\"" . $linha[’id_pais’] . "\">" . $linha[’pais’] . "</option>";
    }

    I need include any file? Why the query doesn’t work?
      • 26903
      • 1,336 Posts
      Don’t you get an error here? Shouldn’t
      $mydb->connect($host='localhost',$dbase='oprc', $uid='root',$pwd='');
      

      be
      $mydb->connect($host='localhost',$dbase='oprc', $uid='root',$pwd=''");
      


      besides anything else.
        Use MODx, or the cat gets it!
        • 27449
        • 211 Posts
        but I still have the same problem :S
        I don’t understand, I don’t have any error... but the query doesn’t return anything

        I think the problem it’s because I have a link at anoyher page,backend.php : ../assets/modules/resorts/actualiza.php?valor=$valor
        because the query work on this page, but doesn’t work at the current page, actualiza.php

        You undertand? :S
          • 26903
          • 1,336 Posts
          Sorry, my bad, your code itself s Ok, maybe a context thing, your backend.php file might be including something the query needs, that its not getting standalone.
            Use MODx, or the cat gets it!
            • 27449
            • 211 Posts
            but the value $_GET[’continente’] it’s correct....
            I don’t understand why the query work in backend.php and not work in the file actualiza.php huh
              • 27449
              • 211 Posts
              I tried to run another query:

              $modx->db->connect(’localhost’, ’oprc’, ’root’, ’’, true);
              $res = $modx->db->select(’*’, ’pais’);
              while($tmp = $modx->db->getRow($res, ’pais’))
              {
              echo $tmp[’pais’];
              }

              but when I execute I have an error: Call to a member function connect() on a non-object in C:\wamp\www\modx-OPRC\assets\modules\resorts\actualiza.php on line 2

              What’s happening?
                • 7231
                • 4,205 Posts
                I think you need to add global $modx; when using the api in a module out of context.

                Try:
                global $modx;
                $modx->db->connect('localhost', 'oprc', 'root', '', true);
                $res = $modx->db->select('*', 'pais');
                while($tmp = $modx->db->getRow($res, 'pais'))
                {
                   echo $tmp['pais'];
                }


                Are you accessing the same database as modx, or is this a second db?
                  [font=Verdana]Shane Sponagle | [wiki] Snippet Call Anatomy | MODx Developer Blog | [nettuts] Working With a Content Management Framework: MODx

                  Something is happening here, but you don&#39;t know what it is.
                  Do you, Mr. Jones? - [bob dylan]
                  • 27449
                  • 211 Posts
                  how?