We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 1778
    • 659 Posts
    By the way if you just want to iterate through a table you can do it without writing any code just using the snippet Rowboat (http://rtfm.modx.com/display/ADDON/Rowboat.Rowboat) you can find it at http://modx.com/extras/package/rowboat (or install via package management of course).

    I encourage you to use google translation on the rtfm ( http://translate.google.cz) wink
    Have swing
      • 24075
      • 83 Posts
      Hi!

      Little formating last code (with $modx->getCollection):

      <?php
      $path = MODX_CORE_PATH . 'components/pepish2/';
      $result = $modx->addPackage('pepish2',$path . 'model/','pp_');
      
      echo 'Pomocné a informační údaje <br><hr>';
      echo '$result: '.$result.'<br>';
      echo '$path: '.$path.'<br>';
      
      if($result){
        $c = $modx->newQuery('Galerie');
        $c->where(array(
          'name_cz' => 'Šidélko brvonohé',
          'kde' => 'Průhonice',
      ));
      
        $c->sortby('galerie_id','ASC');
        $pokus = $modx->getCollection('Galerie',$c);
      }
      
       echo '$pokus: '.$pokus.'<br>';
       echo 'Total: '.count($pokus).'<br><hr>';
      
      echo '<div id="db">
      <table align="center" width="640" border="1" bordercolor="#FFCC00" bgcolor="#008080">';
      foreach ($pokus as $pok) {
        echo '<tr>';
        echo '<td> '.$pok->get('galerie_id').'</td>'."\n";
        echo '<td> '.$pok->get('name_cz').'</td>'."\n";
        echo '<td> '.$pok->get('name_lat').'</td>'."\n";
        echo '<td> '.$pok->get('kde').'</td>'."\n";
        echo '</tr>';
      }
      echo '</table>
      </div> <!-- end db -->';


      Result here:
      http://puschpull.org/modx_rev/bob-galerie
      :) [ed. note: puschpull last edited this post 14 years, 7 months ago.]
        Petr Püschel, Czech Republic
        <hr>
        http://puschpull.org
        <hr>
        • 24075
        • 83 Posts
        This script is not correctly!?:

        <?php
        $path = MODX_CORE_PATH . 'components/pepish2/';
        $result = $modx->addPackage('pepish2',$path . 'model/','pp_');
        
        if($result){
          $c = $modx->newQuery('Galerie');
          $c->select(array('galerie_id','name_cz','kde'));
          $c->where(array(
            'name_cz' => 'abc',
            'kde' => 'def',
        ));
          $c->sortby('galerie_id','ASC');
          $pokus = $modx->getCollection('Galerie',$c);
        }
           
        echo '<div id="db">
        <table align="center" width="640" border="1" bordercolor="#FFCC00" bgcolor="#008080">';
        foreach ($pokus as $pok) {
          echo '<tr>';
          echo '<td> '.$pok->get('galerie_id').'</td>'."\n";
          echo '<td> '.$pok->get('name_cz').'</td>'."\n";
          echo '<td> '.$pok->get('name_lat').'</td>'."\n";
          echo '<td> '.$pok->get('kde').'</td>'."\n";
          echo '</tr>';
        }
        echo '</table>
        </div> <!-- end db -->';


        problem is in line:
          $c->select(array('galerie_id','name_cz','kde'));


        why?
          Petr Püschel, Czech Republic
          <hr>
          http://puschpull.org
          <hr>
          • 1778
          • 659 Posts
          you don't need it
            • 24075
            • 83 Posts
            Quote from: anso at Mar 05, 2012, 11:56 AM
            you don't need it

            aha

             $c = $modx->newQuery('Galerie');
              $c->select(array('galerie_id','name_cz','kde'));


            is not correctly


            $c = $modx->newQuery('Galerie');

            is synonymum
            like
            SELECT * FROM table ....


            Yes?
              Petr Püschel, Czech Republic
              <hr>
              http://puschpull.org
              <hr>
              • 1778
              • 659 Posts
              Not really...

              with SELECT * FROM table ....you querying datas in a SQL table...

              with $modx->newQuery('Galerie') you're querying an OBJECT (or all the objects) with all its attributes and restrict them with 'where'...

              You're querying a collection of objects where each object has its own attributes,

              But since mySQL is a relationnal database and not an object database, an object is often 'translated' in table and columns with relations defined...

              Not sure I'm very clear but I try to be simple in my explanations....

              As defined by Wikipedia:

              An object-relational database (ORD), or object-relational database management system (ORDBMS), is a database management system (DBMS) similar to a relational database, but with an object-oriented database model: objects, classes and inheritance are directly supported in database schemas and in the query language. In addition, it supports extension of the data model with custom data-types and methods.

              Basically, tables in SQL databases become classes that can contain table-specific methods, inherit from base classes, and much more.
                • 24075
                • 83 Posts
                  Petr Püschel, Czech Republic
                  <hr>
                  http://puschpull.org
                  <hr>
                  • 24075
                  • 83 Posts
                  Once question:

                  How is possible display ( echo $query; huh) structure resultant QUERY ??
                  for example
                  SELECT * FROM `pp_galerie` WHERE `name_cz` LIKE 'V%' LIMIT 16;

                  from this code:

                  <?php
                  $path = MODX_CORE_PATH . 'components/pepish2/';
                  $result = $modx->addPackage('pepish2',$path . 'model/','pp_');
                  echo 'Pomocné a informační údaje <br><hr>';
                  echo '$result: '.$result.'<br>';
                  echo '$path: '.$path.'<br>';
                  
                  if($result){
                    $c = $modx->newQuery('Galerie');
                    $c->where(array(
                      'name_cz:LIKE' => 'V%',
                  ));
                    $c->sortby('galerie_id','ASC');
                    $c->limit('16');
                     echo '$c: '.$c.'<br>';  // nothing display QUERY !!
                    $pokus = $modx->getCollection('Galerie',$c);
                  }
                   echo '$pokus: '.$pokus.'<br>';
                   echo 'Total: '.count($pokus).'<br><hr>';
                     
                  echo '<div id="db">
                  <table align="center" width="640" border="1" bordercolor="#FFCC00" bgcolor="#008080">';
                  foreach ($pokus as $pok) {
                    echo '<tr>';
                    echo '<td> '.$pok->get('galerie_id').'</td>'."\n";
                    echo '<td> '.$pok->get('name_cz').'</td>'."\n";
                    echo '<td> '.$pok->get('name_lat').'</td>'."\n";
                    echo '<td> '.$pok->get('kde').'</td>'."\n";
                    echo '</tr>';
                  }
                  echo '</table>
                  </div> <!-- end db -->';



                  Thanks!
                    Petr Püschel, Czech Republic
                    <hr>
                    http://puschpull.org
                    <hr>
                    • 4172
                    • 5,888 Posts
                    try:
                    $c->prepare();
                    echo '$c: '.$c->toSql().' ';  // nothing display QUERY !!
                      -------------------------------

                      you can buy me a beer, if you like MIGX

                      http://webcmsolutions.de/migx.html

                      Thanks!
                      • 24075
                      • 83 Posts
                      Thanks.


                      result is now:
                      $c: SELECT `Galerie`.`galerie_id` AS `Galerie_galerie_id`, `Galerie`.`title` AS `Galerie_title`, `Galerie`.`name_cz` AS `Galerie_name_cz`, `Galerie`.`name_lat` AS `Galerie_name_lat`, `Galerie`.`kategorie` AS `Galerie_kategorie`, `Galerie`.`kde` AS `Galerie_kde`, `Galerie`.`kdy` AS `Galerie_kdy`, `Galerie`.`upload_date_time` AS `Galerie_upload_date_time`, `Galerie`.`copyright` AS `Galerie_copyright`, `Galerie`.`permission` AS `Galerie_permission`, `Galerie`.`display` AS `Galerie_display`, `Galerie`.`short_text` AS `Galerie_short_text`, `Galerie`.`picture_name` AS `Galerie_picture_name`, `Galerie`.`thumbs_name` AS `Galerie_thumbs_name`, `Galerie`.`path_large` AS `Galerie_path_large`, `Galerie`.`path_thumbs` AS `Galerie_path_thumbs` FROM `pp_galerie` AS `Galerie` WHERE `Galerie`.`name_cz` LIKE 'V%' ORDER BY galerie_id ASC LIMIT 16



                      This short version is not possible?

                      SELECT * FROM `pp_galerie` WHERE `name_cz` LIKE 'V%' LIMIT 16;
                        Petr Püschel, Czech Republic
                        <hr>
                        http://puschpull.org
                        <hr>