We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 24075
    • 83 Posts
    Hello

    I have very simple question:
    How i make in MODx Rev (2.2.0) and xPDO this simple task

    table category:
    id	smallint(4) Auto Increment	 
    name	varchar(64)	 
    name_alt	varchar(128)	 
    parent_id	smallint(4) NULL	 
    view	smallint(2) [1]


    SQL :
    SELECT id, name
    FROM `category`
    ORDER BY name ASC
    LIMIT 8


    $dsn = 'mysql:host=mysql.server.xyz;dbname=database_name;port=3306;charset=utf-8';
    $xpdo = new xPDO($dsn,'user','password');
    
    // echo $o=($xpdo->connect()) ? 'Connected' : 'Not Connected';
    
    $output = '';
    
    $dotaz = $xpdo->newQuery('category');
    
    $dotaz->where(array(
       'id' => $id,
       'name' => $name
    ));
    
    $dotaz->sortby('name','ASC');
    $dotaz->limit(8);
    
    $vysledek = $xpdo->getCollection('category',$dotaz);
    
    foreach($vysledek as $vysl) {
        $output .= 'ID' . $box->get('id').'Name ' . $box->get('name');
    }
    
    return $output;



    Thank for any ideas
    (I'm beginner in xPDO, in Evolution or older version Revolution this Task is simple, with use xPDO have i problem]
      Petr Püschel, Czech Republic
      <hr>
      http://puschpull.org
      <hr>
      • 22303 MODX Staff
      • 10,725 Posts
      Where are you specifying/loading your package of classes representing this table?
        • 24075
        • 83 Posts
        $dotaz->select($xpdo->getSelectColumns('category','category','',array('id','name')));


        ?
          Petr Püschel, Czech Republic
          <hr>
          http://puschpull.org
          <hr>
          • 24075
          • 83 Posts
          I need help
          I need result for this simple table
          I need basic idea about workings this SQL Query (with xPDO)
            Petr Püschel, Czech Republic
            <hr>
            http://puschpull.org
            <hr>
            • 33968
            • 863 Posts
            You'll need to do a bit of work setting things up before you can use xPDO methods on your custom table. The extra effort is well worth it however. Have a read through the docs and try out the example if you're not familiar with PDO:

            http://rtfm.modx.com/display/revolution20/Using+Custom+Database+Tables+in+your+3rd+Party+Components

            If you're finding that a bit much, you could also consider using the RowBoat snippet if you're not trying to do anything too complex.
              • 22303 MODX Staff
              • 10,725 Posts
              Just write a SQL query and use the PDO methods available from xPDO, e.g.

              <?php
              $output = array();
              $pdoStmt = $xpdo->prepare("SELECT * FROM category WHERE `id` = ? AND `name` = ? ORDER BY `name` ASC LIMIT 8");
              if ($pdoStmt->execute(array($id, $name))) {
                  while ($row = $pdoStmt->fetch(PDO::FETCH_OBJ)) {
                      $output[] = "ID {$row->id} - Name {$row->name}";
                  }
              }
              return implode("\n", $output);
              
                • 24075
                • 83 Posts
                Aha
                :(
                hmmm

                simple SQL Query is not simple code in xPDO

                one snippet where simulated simple Query
                SELECT id, name FROM `category` ORDER BY name ASC LIMIT 8

                and his display in tabular form on screen

                This it is not possible in simple code in xPDO ?


                Lucas: thanks for this links
                  Petr Püschel, Czech Republic
                  <hr>
                  http://puschpull.org
                  <hr>
                  • 22303 MODX Staff
                  • 10,725 Posts
                  If you want to have an OO API into your model rather than write direct SQL code, then you generate the model code from an xPDO XML schema. At that point, the CRUD code is very simple. Just depends on what you are looking for, a quick way to query ad hoc tables or a reusable, extensible CRUD API.
                    • 24075
                    • 83 Posts
                    Last year I programme for my brother these pages:
                    http://dawep.net/new.php

                    Behind using MySQL / PHP

                    Also I him pre - set full administration whole gallery, editing pictures, possibilities as change navigation menu.
                    Some bases I know.

                    MODx Revolution me very interest and I'm enjoying his possibilities
                    I wanted such gallery and administration reshape to the MODx

                    But mine problem with xPDO me absolutely stopped in of my attempts.

                    I'll with pleasure behind each help, to overcame (I hope that only initial) problems with teaching basis xPDO

                    P.S.: I am sorry for his English, doesn't speak English
                      Petr Püschel, Czech Republic
                      <hr>
                      http://puschpull.org
                      <hr>
                      • 24075
                      • 83 Posts
                      Lusac:

                      http://rtfm.modx.com/display/ADDON/Rowboat.Rowboat
                      works fine
                      :)

                      but i need learn very more about xPDO and MySQL
                        Petr Püschel, Czech Republic
                        <hr>
                        http://puschpull.org
                        <hr>