简体   繁体   中英

How to export data from user modx database to form?

I've table in modx database (orders), and i need to export data from that db to table at site. I pushing into db with following snipept

<?php
function agregarCargas( &$fields )
    {
        global $modx;
        // Init our array
        $dbTable = array();
                $dbTable['subject'] = $modx->db->escape($fields['subject']);
        $dbTable['fullname'] = $modx->db->escape($fields['fullname']);
        $dbTable['message']     = $modx->db->escape($fields['message']);
        // Run the db insert query
        $dbQuery = $modx->db->insert($dbTable, 'orders' );
        return true;
    }
?>

How can i export from DB? Snippet or? Thanks.

(Old thread, just for new folks trying to tackle this...)

Looking at the API you're using I'm guessing you are stuck with an old MODx version. (Evolution)

You should take a look at the API::DB docs for MODX Evolution

Something along the lines of the following would fill your HTML table:

$res        = $modx->db->select("subject, fullname", 'orders');
$res_rows   = $modx->db->makeArray($res);
$rows       = "";
for($n=0;$n<count($res_rows);$n++){
    $rows  .= "<tr><td>".$res_rows['subject']."</td><td>".$res_rows['fullname']."</td></tr>\n";
}
return $rows;

(Of course you should use chunks instead of hardcoded HTML)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM