A
A
Anton Myasnov2019-10-01 20:09:02
MySQL
Anton Myasnov, 2019-10-01 20:09:02

How to get data from a table in a database in Modx Revolution?

Hello.
There is a site on modx revo. In phpMyAdmin, in the database that was created for the site, I added a table.
I need to get data from this table and display it in a snippet on the page according to the condition (for example, if the table column has a value of 1, then I display it). How to do it and what to use, in which direction to look?
PS I googled ways through xPDO, but in all examples they show how to get any data from resources or other things, which I can do myself in standard ways, but I didn’t find how to get it from database tables. Maybe I'm writing the query incorrectly, since my level of knowledge of the database and SQL is limited to SELECT * FROM TABLE

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry, 2019-10-02
@i__dmitry

xPDO quite allows you to work with arbitrary tables from the database. Link for review.
Example:

$sql = "SELECT * FROM modx_users WHERE active = 1";
// Вариант 1.
$statement = $modx->query($sql);
$users = $statement->fetchAll(PDO::FETCH_ASSOC);
foreach ($users as $user) {
    print $user['username'] .'<br/>';
}
// Вариант 2. Если не нужно зачитывать данные в массив
foreach ($modx->query($sql) as $user) {
    print $user['username'] .'<br/>';
}

If you want to work with data from your table as MODX objects, then you need to deal with packages. Link .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question